远神_
远神_
全部文章
分类
题解(29)
归档
标签
去牛客网
登录
/
注册
远神_的博客
全部文章
(共29篇)
题解 | #链表的奇偶重排#
odd 连接奇数节点even 连接偶数节点最终让odd尾指向even头就好了 class Solution { public: ListNode* oddEvenList(ListNode* head) { if(!head || head->next == nullp...
2021-07-26
0
281
题解 | #用两个栈实现队列#
stack1用于出栈stack2用于入栈 stack1出栈之前,stack2要全部挪入stack1stack2入栈之前,stack1要全部挪入stack2 class Solution { public: //sour-->des void move(stack<int&...
2021-07-26
0
322
题解 | #斐波那契数列#
递归 class Solution { public: int Fibonacci(int n) { if(n == 0)return 0; if(n == 1 || n == 2)return 1; return Fibonacci(n-1)...
2021-07-26
0
242
题解 | #进制转换#
除和取余 class Solution { public: string solve(int M, int N) { if(M == 0) return "0"; bool neg = false; if(M<0){ ...
2021-07-26
0
303
题解 | #跳台阶#
动态规划 class Solution { public: int jumpFloor(int number) { vector<int> F(number, 0); F[0] = 1; F[1] = 2; for(...
2021-07-26
0
249
题解 | #判断链表中是否有环#
哈希方式 class Solution { public: bool hasCycle(ListNode *head) { unordered_map<ListNode *, bool> m; while(head){ if...
2021-07-26
0
297
题解 | #子数组的最大累加和问题#
动态规划:动态转移方程:F[i] = max(a[i], F[i-1]+a[i]) class Solution { public: int maxsumofSubarray(vector<int>& arr) { vector<int> F(...
2021-07-26
0
265
题解 | #矩阵的最小路径和#
动态规划 class Solution { public: int minPathSum(vector<vector<int> >& matrix) { vector<vector<int>> res(matrix); ...
2021-07-26
0
310
题解 | #买卖股票的最好时机#
动态规划dp[i][0]代表下标为i天的时候,手上没有股票的最大收益dp[i][1]代表i天的时候手上有股票最小收益是多少 初始状态dp[0][0]=0,dp[i][1]=prices[0] 状态转移方程:dp[i][0] = max(dp[i-1][0], prices[i]-dp[i-1][1]...
2021-07-26
0
285
题解 | #两数之和#
元素和差的值建立映射关系,如果差值能在元素中找到说明就是加数 注意:差值和元素值相同时,这个元素值不能使用 class Solution { public: int find(vector<pair<int, int>>& m, int f, int a){ ...
2021-07-25
0
322
首页
上一页
1
2
3
下一页
末页