- 博客(63)
- 问答 (2)
- 收藏
- 关注
原创 152. 乘积最大子序列
class Solution {public: int max(int a, int b, int c) { int tmp; if (a > b) tmp = a; else tmp = b; if (tmp > c) return tmp; else return c; } ...
2019-12-21 13:58:25
200
原创 221. 最大正方形
class Solution {public: int maximalSquare(vector<vector<char>>& matrix) { if (matrix.empty() || matrix[0].empty()) return 0; vector<vector<int>> dp(...
2019-12-21 13:58:24
232
原创 217. 存在重复元素
class Solution {public: bool containsDuplicate(vector<int>& nums) { if(!nums.size()) return false; sort(nums.begin(),nums.end()); vector<int>::...
2019-12-21 13:58:16
196
原创 300. 最长上升子序列
class Solution {public: int lengthOfLIS(vector<int>& nums) { if (nums.empty()) return 0; int maxLength = 1; int* dp = new int[nums.size()]; for (int i...
2019-12-21 13:58:11
144
原创 279. 完全平方数
class Solution {public: int numSquares(int n) { int* dp = new int[n + 1]; for (int i = 0; i <= n; ++i) { dp[i] = i; for (int j = 1; j*j <= i; ++j)...
2019-12-21 13:58:10
137
原创 303. 区域和检索 - 数组不可变
class NumArray {public: int* dp; NumArray(vector<int>& nums) { if(nums.empty()) return; dp=new int[nums.size()]{0}; for(int i=0;i<nums.size();++i){ ...
2019-12-21 13:58:07
132
原创 309. 最佳买卖股票时机含冷冻期
class Solution {public: int maxProfit(vector<int>& prices) { vector<vector<int>> dp(prices.size() + 1, vector<int>(2)); dp[0][1] = INT_MIN; ...
2019-12-21 13:57:52
128
原创 714. 买卖股票的最佳时机含手续费
class Solution {public: int maxProfit(vector<int>& prices, int fee) { vector<vector<int>> dp(prices.size() + 1, vector<int>(2)); dp[0][1] = INT_MIN; ...
2019-12-21 13:57:43
158
原创 213. 打家劫舍 II
class Solution {public: int rob(vector<int>& nums) { if (nums.empty()) return 0; if(nums.size()==1) return nums[0]; int* dp = new int[nums.size() + 1]; ...
2019-12-21 13:57:34
118
原创 198. 打家劫舍
class Solution {public: int maxProfit_inf(vector<int>& prices) { int** dp = new int*[prices.size() + 1]; for (int i = 0; i < prices.size() + 1; ++i) { ...
2019-12-21 13:57:23
167
原创 143. 重排链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: void reor...
2019-08-30 10:03:21
132
原创 141. 环形链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasC...
2019-08-30 10:03:16
128
原创 139. 单词拆分
class Solution {public: bool wordBreak(string s, vector<string>& wordDict) { if (s.empty() || wordDict.empty()) return false; unordered_set<string> dic; ...
2019-08-30 10:03:06
217
原创 138. 复制带随机指针的链表
/*// Definition for a Node.class Node {public: int val; Node* next; Node* random; Node() {} Node(int _val, Node* _next, Node* _random) { val = _val; next = ...
2019-08-30 10:02:55
120
原创 134. 加油站
class Solution {public: int canCompleteCircuit(vector<int>& gas, vector<int>& cost) { int cur_tank = 0, total_tank = 0; int start_pos = 0; for (int ...
2019-08-30 10:02:51
124
原创 123. 买卖股票的最佳时机 III
class Solution {public: int maxProfit(vector<int>& prices) { vector<vector<vector<int>>> dp(prices.size() + 1); for (int i = 0; i < dp.size(); +...
2019-08-30 10:02:46
121
原创 122. 买卖股票的最佳时机 II
class Solution {public: int maxProfit(vector<int>& prices) { int** dp = new int*[prices.size() + 1]; for (int i = 0; i < prices.size() + 1; ++i) { dp[...
2019-08-30 10:02:42
125
原创 121. 买卖股票的最佳时机
class Solution {public: int maxProfit(vector<int>& prices) { int** dp = new int*[prices.size() + 1]; for (int i = 0; i < prices.size() + 1; ++i) { dp[...
2019-08-30 10:02:33
129
原创 120. 三角形最小路径和
class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { if (triangle.empty()) return 0; int n = triangle.size(); int* res = new int[n]...
2019-08-30 10:02:25
139
原创 翻转双向链表~~~~~~~~~~~~~~~~~~~~~~~~~~!~~
struct Node { Node(int v) : value(v), pre(NULL), next(NULL) {} int value; Node *pre; Node *next;};Node* reverse_list(Node *node) { Node* NodePre = nullptr; Node* NodeCurrent = node; while (N...
2019-08-30 10:02:10
173
原创 109. 有序链表转换二叉搜索树
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for a binary tree no...
2019-08-29 09:27:17
136
原创 92. 反转链表 II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-29 09:27:13
129
原创 86. 分隔链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-29 09:27:08
138
原创 83. 删除排序链表中的重复元素
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-29 09:27:05
144
原创 82. 删除排序链表中的重复元素 II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-29 09:26:59
129
原创 70. 爬楼梯
class Solution {public: int climbStairs(int n) { if (n == 0) return 0; if (n == 1) return 1; if (n == 2) return 2; int resNMinus1 = 2,resNMinus2=1,resN; ...
2019-08-29 09:26:56
143
原创 64. 最小路径和
class Solution {public:int minPathSum(vector<vector<int>>& grid) { if (grid.empty()) return 0; int res[1000]; int rowCount = grid.size(); int colCount = grid[0].size(); res[0...
2019-08-29 09:26:52
240
原创 63. 不同路径 II
class Solution {public:int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { if (obstacleGrid.empty()) return 0; unsigned int res[101][101]; memset(res, 0, sizeof(r...
2019-08-29 09:26:47
136
原创 62. 不同路径
class Solution {public:int uniquePaths(int m, int n) { int res[101][101]; for (int j = 0; j< m; ++j) { res[0][j]=1; } for (int i = 0; i < n; ++i) { res[i][0] = 1; } for (int i = 1...
2019-08-29 09:26:42
95
原创 61. 旋转链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-29 09:26:31
123
原创 55. 跳跃游戏
class Solution {public: bool canJump(vector<int>& nums) { if (nums.empty()) return false; bool* dp = new bool[nums.size()]; dp[nums.size() - 1] = true; ...
2019-08-24 13:18:44
141
原创 27. 移除元素
class Solution {public: int removeElement(vector<int>& nums, int val) { if (nums.empty()) return 0; int slow = 0; for (int fast = 0; fast < nums.size(); ++fast) { if (nums[f...
2019-08-24 13:18:40
116
原创 28.实现 strStr()
class Solution {public: int strStr(string haystack, string needle) { if (needle.empty()) return 0; int j,k; for (int i = 0; i <= (int)haystack.length() - (int)needle.length(); ++i) { ...
2019-08-24 13:18:37
204
原创 26. 删除排序数组中的重复项
class Solution {public: int removeDuplicates(vector<int>& nums) { if (nums.empty()) return 0; int slow = 0; for (int fast = 1; fast < nums.size(); ++fast) { if (nums[fast] !...
2019-08-24 13:18:31
114
原创 25. K 个一组翻转链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-24 13:18:27
137
原创 24. 两两交换链表中的节点
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-24 13:18:23
112
原创 21. 合并两个有序链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-24 13:18:20
104
原创 20. 有效的括号
class Solution {public: bool isValid(string s) { stack<char> brackets; map<char, int> leftBra{ {'{',1},{'[',2},{'(',3} }; unordered_map<char,int> rightBra{ { '}',1 }...
2019-08-24 13:18:16
201
原创 19. 删除链表的倒数第N个节点
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode*...
2019-08-24 13:18:07
117
原创 17. 电话号码的字母组合
class Solution {public: vector<string> letterCombinations(string digits) { vector<string> res; vector<char> letter; if (digits.length() == 0) return res; if (digits[0] -...
2019-08-24 13:17:59
110
空空如也
一个可触摸精灵影响到另一个可触摸精灵
2016-07-18
学习lua时用player3创建项目后。我的项目栏里是空的
2016-04-06
TA创建的收藏夹 TA关注的收藏夹
TA关注的人