Commit bdbb481f authored by zhayao's avatar zhayao
Browse files

fixed conflict

parents 47030270 871dfaf6
......@@ -1660,43 +1660,40 @@ public:
Best Time to Buy and Sell Stock
Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Not 7-1 = 6, as selling price needs to be larger than buying price.
class Solution {
public:
int maxProfit(vector<int>& prices) {
int min = INT_MAX;
int profit = 0;
for(int i=0; i<prices.size(); i++){
if(prices[i] < min){
min = prices[i];
}
else{
profit = std::max(profit, prices[i] - min);
}
}
return profit;
}
};
Coin Change
Word Break
class Solution {
public:
bool wordBreak(string s, vector<string>& wordDict) {
unordered_set<string> dict;
for(auto &key: wordDict){
dict.insert(key);
int coinChange(vector<int>& coins, int amount) {
if (amount == 0) return 0;
vector<int> table(amount+1, INT_MAX);
table[0] = 0;
for(int i=0; i<table.size(); i++){
}
vector<bool> matched(s.size(), false);
int last_match_pos = 0;
for(int i=0; i<s.size(); i++){
string sub = s.substr(last_match_pos, i-last_match_pos);
cout<<sub<<endl;
auto it = dict.find(sub);
if(it != dict.end()){
dict.
for(int inner=0; inner<sub.size(); inner++){
matched[inner+last_match_pos] = true;
}
last_match_pos = i+1;
}
}
for(int i=0; i<matched.size(); i++){
if(!matched[i]) return false;
}
return true;
}
};
......@@ -1704,6 +1701,5 @@ public:
//
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment