随笔分类 -  LeetCode题解

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 阅读全文
posted @ 2020-04-12 17:44 Jinxiaobo0509 阅读(105) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool isPowerOfTwo(int n) 5 { 6 return n > 0 && (n & n - 1) == 0; 7 } 8 }; 1 class Solution 2 { 3 public: 4 bool isPow 阅读全文
posted @ 2020-04-12 16:04 Jinxiaobo0509 阅读(121) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int kthSmallest(TreeNode* root, int k) 5 { 6 stack<TreeNode*> s; 7 TreeNode *cur = root; 8 while(!s.empty() || cur) 9 阅读全文
posted @ 2020-04-12 13:58 Jinxiaobo0509 阅读(183) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 vector<int> majorityElement(vector<int>& nums) 5 { 6 vector<int> res; 7 if (nums.empty()) return res; 8 // 初始化两个候选人ca 阅读全文
posted @ 2020-04-12 13:31 Jinxiaobo0509 阅读(140) 评论(0) 推荐(0)
摘要:1 //简单题 2 class Solution 3 { 4 public: 5 vector<string> summaryRanges(vector<int>& nums) 6 { 7 vector<string> res; 8 if(nums.empty()) return res; 9 ve 阅读全文
posted @ 2020-04-12 11:59 Jinxiaobo0509 阅读(155) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int calculate(string s) 5 { 6 s += "+";//1、最后一位加一个"+" 7 if (s.empty()) return 0; 8 stack<int> vals; 9 stack<char> ops 阅读全文
posted @ 2020-04-12 11:35 Jinxiaobo0509 阅读(131) 评论(0) 推荐(0)
摘要:1 class MyQueue 2 { 3 stack<int> s1,s2; 4 public: 5 MyQueue() {} 6 7 void push(int x) 8 { 9 s1.push(x); 10 } 11 12 int pop() 13 { 14 while(!s1.empty() 阅读全文
posted @ 2020-04-11 23:17 Jinxiaobo0509 阅读(116) 评论(0) 推荐(0)
摘要:1 class MyStack 2 { 3 queue<int> q1;//数据队列 4 queue<int> q2;//临时队列 5 public: 6 MyStack() {} 7 8 void push(int x) 9 { 10 q1.push(x); 11 } 12 13 int pop( 阅读全文
posted @ 2020-04-11 22:36 Jinxiaobo0509 阅读(93) 评论(0) 推荐(0)
摘要:1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), 阅读全文
posted @ 2020-04-11 19:49 Jinxiaobo0509 阅读(105) 评论(0) 推荐(0)
摘要:1 //从四个方向比较,只要任意一个方向不满足,就不重叠 2 class Solution 3 { 4 public: 5 int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) 6 { 7 long long 阅读全文
posted @ 2020-04-11 18:17 Jinxiaobo0509 阅读(312) 评论(0) 推荐(0)
摘要:1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), 阅读全文
posted @ 2020-04-11 17:32 Jinxiaobo0509 阅读(150) 评论(0) 推荐(0)
摘要:1 //dp(i, j)=min(dp(i−1, j), dp(i−1, j−1), dp(i, j−1))+1 2 class Solution 3 { 4 public: 5 int maximalSquare(vector<vector<char>>& matrix) 6 { 7 if(mat 阅读全文
posted @ 2020-04-11 16:29 Jinxiaobo0509 阅读(134) 评论(0) 推荐(0)
摘要:1 //用multimap就可以解决 2 class Solution 3 { 4 public: 5 bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) 6 { 7 if(nums.empty()) return 阅读全文
posted @ 2020-04-11 14:09 Jinxiaobo0509 阅读(138) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool containsNearbyDuplicate(vector<int>& nums, int k) 5 { 6 unordered_map<int,int> hash; 7 for(int i = 0;i < nums.si 阅读全文
posted @ 2020-04-10 16:26 Jinxiaobo0509 阅读(118) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool containsDuplicate(vector<int>& nums) 5 { 6 unordered_map<int,int> hash; 7 for(auto a : nums) 8 { 9 if(++ hash[a] 阅读全文
posted @ 2020-04-10 16:17 Jinxiaobo0509 阅读(64) 评论(0) 推荐(0)
摘要:1 // [1,3],[4,7],[9,9] 2 // L[1] = 3,L[4] = 7,L[9] = 9; 3 // R[3] = 1,R[7] = 4,R[9] = 9; 4 class SummaryRanges 5 { 6 map<int,int> L,R; 7 unordered_set 阅读全文
posted @ 2020-04-10 15:15 Jinxiaobo0509 阅读(169) 评论(0) 推荐(0)
摘要:1 class MedianFinder 2 { 3 priority_queue<int,vector<int>,greater<int>> up;//小根堆 4 priority_queue<int> down;//大根堆 5 public: 6 MedianFinder() {} 7 8 vo 阅读全文
posted @ 2020-04-10 11:08 Jinxiaobo0509 阅读(109) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 struct cmp 4 { 5 bool operator()(pair<string,int> const &left,pair<string,int> const &right) 6 { 7 if(left.second == right.seco 阅读全文
posted @ 2020-04-09 22:21 Jinxiaobo0509 阅读(154) 评论(0) 推荐(0)
摘要:1 class UnionFind 2 { 3 public: 4 vector<int> parent; // 存储若干棵树 5 int count; 6 UnionFind(int n) 7 { 8 count = n; 9 for (int i = 0; i < n; i++) parent. 阅读全文
posted @ 2020-04-09 21:25 Jinxiaobo0509 阅读(178) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 vector<int> p; 4 5 int find(int x) 6 { 7 if(p[x] != x) p[x] = find(p[x]); 8 return p[x]; 9 } 10 public: 11 int findCircleNum(ve 阅读全文
posted @ 2020-04-09 20:46 Jinxiaobo0509 阅读(104) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页