随笔分类 - LeetCode题解
摘要:1 class Solution 2 { 3 void calc(stack<char>& op,stack<int>& num) 4 { 5 int y = num.top(); 6 num.pop(); 7 int x = num.top(); 8 num.pop(); 9 if(op.top(
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<vector<int>> insert(vector<vector<int>>& nums, vector<int>& newInterval) 5 { 6 nums.push_back(newInterval); 7
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int numSubarraysWithSum(vector<int>& nums, int k) 5 { 6 unordered_map<int,int> hash;// 和+次数 7 hash[0] = 1; 8 9 int re
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int projectionArea(vector<vector<int>>& grid) 5 { 6 int m = grid.size(),n = grid[0].size(); 7 int res = 0; 8 for(int
阅读全文
摘要:1 // nums[0] = 9; // 1-9 2 // nums[1] = 90*2; // 10-99 3 // nums[2] = 900*3; // 100-999 4 // nums[3] = 9000*4; // 1000-9999 5 // nums[4] = 90000*5; //
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<double> calcEquation(vector<vector<string>> &equations, vector<double> &values, vector<vector<string>> &querie
阅读全文
摘要:1 class Solution 2 { 3 unordered_map<int,vector<int>> hash;// 对应的数 + /下标(可能有重复数)/ 4 public: 5 Solution(vector<int>& nums) 6 { 7 for(int i = 0;i < nums
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int integerReplacement(int n) 5 { 6 return DFS(n); 7 } 8 9 long long DFS(long long n) 10 { 11 if(n == 1) return 0; 12
阅读全文
摘要:1 // F[i + 1] - F[i] = sum - n * A[n - 1 - i] 2 class Solution 3 { 4 public: 5 int maxRotateFunction(vector<int>& A) 6 { 7 if(A.empty()) return 0; 8 i
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int longestSubstring(string s, int k) 5 { 6 if(s.empty()) return 0; 7 vector<int> hash(26); 8 for(auto a : s) hash[a
阅读全文
摘要:1 class Solution 2 { 3 public: 4 bool validUtf8(vector<int>& data) 5 { 6 int n = 0; 7 for(int i = 0;i < data.size();i ++) 8 { 9 if(n > 0) 10 { 11 if(d
阅读全文
摘要:1 class Solution 2 { 3 public: 4 char findTheDifference(string s, string t) 5 { 6 unordered_map<char,int> hash; 7 for(auto a : s) hash[a] ++; 8 for(au
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int firstUniqChar(string s) 5 { 6 unordered_map<char,int> hash; 7 for(auto a : s) hash[a] ++; 8 for(int i = 0;i < s.s
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<int> lexicalOrder(int n) 5 { 6 set<string> hash; 7 vector<int> res; 8 for(int i = 1;i <= n;i ++) 9 { 10 hash.i
阅读全文
摘要:1 class Solution 2 { 3 vector<int> vec; 4 public: 5 Solution(vector<int>& nums) 6 { 7 vec = nums; 8 } 9 10 /** Resets the array to its original config
阅读全文
摘要:1 class Solution 2 { 3 public: 4 bool canConstruct(string ransomNote, string magazine) 5 { 6 unordered_map<char,int> hash_r,hash_m; 7 for(auto a : mag
阅读全文
摘要:1 class Solution 2 { 3 public: 4 ListNode* nod; 5 Solution(ListNode* head) 6 { 7 this->nod = head; 8 } 9 10 int getRandom() 11 { 12 if(nod == NULL) re
阅读全文
摘要:1 class RandomizedSet 2 { 3 unordered_map<int,int> hash; 4 vector<int> nums; 5 public: 6 /** Initialize your data structure here. */ 7 RandomizedSet()
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int kthSmallest(vector<vector<int>>& matrix, int k) 5 { 6 priority_queue<int,vector<int>,greater<int>> pq; 7 int n =
阅读全文
摘要:1 class Solution 2 { 3 vector<vector<int>> memo; 4 public: 5 int getMoneyAmount(int n) 6 { 7 memo = vector<vector<int>>(n + 1,vector<int>(n + 1,-1));
阅读全文

浙公网安备 33010602011771号