上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 23 下一页
摘要: class Solution { public: int rob(vector<int>& nums) { if(nums.size()==0) return 0; if(nums.size()==1) return nums[0]; // dp[i]表示前i间房屋能偷窃到的最高总金额 vector 阅读全文
posted @ 2021-07-21 19:08 三一一一317 阅读(18) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solu 阅读全文
posted @ 2021-07-21 18:33 三一一一317 阅读(12) 评论(0) 推荐(0)
摘要: class MinStack { public: /** initialize your data structure here. */ MinStack() { } stack<int> s; stack<int> mins; void push(int val) { if(mins.empty( 阅读全文
posted @ 2021-07-21 18:16 三一一一317 阅读(30) 评论(0) 推荐(0)
摘要: 标签:动态规划 遍历数组时计算当前最大值,不断更新 令imax为当前最大值,则当前最大值为 imax = max(imax * nums[i], nums[i]) 由于存在负数,那么会导致最大的变最小的,最小的变最大的。因此还需要维护当前最小值imin,imin = min(imin * nums[ 阅读全文
posted @ 2021-07-21 18:01 三一一一317 阅读(50) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : 阅读全文
posted @ 2021-07-21 18:00 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: // /** // * Definition for singly-linked list. // * struct ListNode { // * int val; // * ListNode *next; // * ListNode(int x) : val(x), next(NULL) {} 阅读全文
posted @ 2021-07-21 16:55 三一一一317 阅读(45) 评论(0) 推荐(0)
摘要: class Solution { public: int singleNumber(vector<int>& nums) { // 俩个相同的数异或结果为0, // 任何数与0异或结果为本身 int res = 0; for(int i = 0; i < nums.size(); i++){ res 阅读全文
posted @ 2021-07-21 16:53 三一一一317 阅读(26) 评论(0) 推荐(0)
摘要: class Solution { public: int longestConsecutive(vector<int>& nums) { if(nums.size()==0) return 0; if(nums.size()==1) return 1; sort(nums.begin(), nums 阅读全文
posted @ 2021-07-21 16:46 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: 解析参考: https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/solution/er-cha-shu-zhong-de-zui-da-lu-jing-he-by-leetcode-/ /** * Definition for 阅读全文
posted @ 2021-07-21 16:25 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2021-07-21 14:57 三一一一317 阅读(31) 评论(0) 推荐(0)
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 23 下一页