随笔分类 - LeetCode题解
摘要:1 class Solution 2 { 3 public: 4 bool increasingTriplet(vector<int>& nums) 5 { 6 int len = nums.size(); 7 if (len < 3) return false; 8 int small = INT
阅读全文
摘要:1 class Solution 2 { 3 public: 4 //欧拉路径 5 vector<string> findItinerary(vector<vector<string>> &tickets) 6 { 7 unordered_map<string, multiset<string>>
阅读全文
摘要:1 //空节点的个数 = 非空节点个数 + 1 2 class Solution 3 { 4 vector<string> res; 5 void spilt(string s,char c) 6 { 7 istringstream iss(s); 8 string temp; 9 while(ge
阅读全文
摘要: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 * };
阅读全文
摘要:1 class Solution 2 { 3 public: 4 bool isPowerOfFour(int num) 5 { 6 return (num > 0) && ((num & (-num)) == num) && (num % 3 == 1); 7 } 8 };
阅读全文
摘要:1 class Solution 2 { 3 public: 4 bool isPowerOfThree(int n) 5 { 6 return n > 0 && 1162261467 % n == 0; 7 } 8 };
阅读全文
摘要:1 class Solution 2 { 3 public: 4 void wiggleSort(vector<int>& nums) 5 { 6 int n = nums.size(); 7 sort(nums.begin(),nums.end()); 8 vector<int> temp; 9
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int coinChange(vector<int>& coins, int amount) 5 { 6 vector<long long> dp(amount + 1,INT_MAX); 7 dp[0] = 0;//总金额为0元所需
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int bulbSwitch(int n) 5 { 6 return sqrt(n); 7 } 8 };
阅读全文
摘要:1、暴力求解 1 class Solution 2 { 3 public: 4 int maxProduct(vector<string>& words) 5 { 6 int n = words.size(); 7 int res = 0; 8 for(auto& a : words) sort(a
阅读全文
摘要:1 //跟264题差不多 2 class Solution 3 { 4 public: 5 int nthSuperUglyNumber(int n, vector<int>& primes) 6 { 7 vector<int> dp(n); 8 dp[0] = 1; 9 vector<int> p
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) 5 { 6 vector<int> ans; 7 if(n == 1) return {0}; 8 v
阅读全文
摘要:1 class Solution 2 { 3 unordered_map<string,vector<char>> hash; 4 public: 5 bool pyramidTransition(string bottom, vector<string>& allowed) 6 { 7 for(a
阅读全文
摘要:1 /** 2 * // This is the interface that allows for creating nested lists. 3 * // You should not implement it, or speculate about its implementation 4
阅读全文
摘要:1 class Solution 2 { 3 public: 4 string decodeString(string s) 5 { 6 int len = s.size(); 7 int num = 0; 8 stack<int> numstack; 9 stack<string> strstac
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<string> letterCasePermutation(string S) 5 { 6 vector<string> res; 7 backTracking(res,S,0); 8 return res; 9 } 1
阅读全文
摘要:1 //hold 持股1、昨天持股,今天什么都不做 2、昨天冻结,今天买入 2 //sold 不持股1、昨天不持股,今天什么都不做 2、昨天持股,今天卖出 3 //rest 冻结1、昨天持股,今天卖出 4 class Solution 5 { 6 public: 7 int maxProfit(ve
阅读全文
摘要:1 //1与2交替出现,从下标2开始 2 class Solution 3 { 4 public: 5 int magicalString(int n) 6 { 7 string s = "122"; 8 for(int i = 2,k = 1;i < n;i ++,k = 3 - k) 9 { 1
阅读全文
摘要:1 class Solution 2 { 3 public: 4 string convertToBase7(int num) 5 { 6 string res; 7 bool a = true; 8 if(num < 0) num = -num,a = false; 9 while(num) 10
阅读全文
摘要:1 class Solution 2 { 3 public: 4 string removeKdigits(string num, int k) 5 { 6 if(num.size() == k) return "0"; 7 stack<char> stk;//单调栈 8 string res; 9
阅读全文

浙公网安备 33010602011771号