摘要:
int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if(prices.empty()) return 0; int buy = prices[0]; int maxprofit = 0; for(int i=1;ibuy) maxprofit += (prices[i]-buy); ... 阅读全文
摘要:
DP int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if(prices.empty()) return 0; vector profit1(prices.size(),0); vector profit2(prices.size(),0); int minPrice = prices[0]; ... 阅读全文
摘要:
需要跳过不是alnum的字符。 bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s.empty()) return true; int i = 0,j = s.size()-1; while(true) { while(i=j) retu... 阅读全文
摘要:
回溯 int sumNumbers(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(!root) return 0; int sum = 0; dfs(root,0,sum); return sum; } void dfs(TreeNode* root,int num, int& sum) { ... 阅读全文
摘要:
回溯 vector > pathSum(TreeNode *root, int sum) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(!root) return res; vector path; dfs(root,sum,path,res); return res; } void ... 阅读全文