-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* @Author: zhaoyang.liang | ||
* @Github: https://github.com/LzyRapx | ||
* @Date: 2020-07-25 12:06:14 | ||
*/ | ||
class Solution { | ||
public: | ||
string reformatDate(string date) { | ||
unordered_map<string, string>mp = {{"Jan", "01"}, {"Feb", "02"}, {"Mar", "03"}, {"Apr", "04"}, | ||
{"May", "05"}, {"Jun", "06"}, {"Jul", "07"}, {"Aug", "08"}, | ||
{"Sep", "09"}, {"Oct", "10"}, {"Nov", "11"}, {"Dec", "12"}}; | ||
string out = "", temp; | ||
stringstream ss(date); | ||
ss >> temp; | ||
if(temp.length()==3) | ||
out+="0"; | ||
out += temp.substr(0, temp.length()-2); | ||
|
||
ss >> temp; | ||
out = mp[temp] + "-" + out; | ||
|
||
ss >> temp; | ||
out = temp + "-" + out; | ||
return out; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* @Author: zhaoyang.liang | ||
* @Github: https://github.com/LzyRapx | ||
* @Date: 2020-07-25 12:09:17 | ||
*/ | ||
class Solution { | ||
public: | ||
int numIdenticalPairs(vector<int>& nums) { | ||
if(nums.size() <= 1) { | ||
return 0; | ||
} | ||
int cnt = 0; | ||
for(int i = 0; i< nums.size(); i++) { | ||
for(int j = i + 1; j < nums.size(); j++) { | ||
if(nums[i] == nums[j]) { | ||
cnt++; | ||
} | ||
} | ||
} | ||
return cnt; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* @Author: zhaoyang.liang | ||
* @Github: https://github.com/LzyRapx | ||
* @Date: 2020-07-25 12:19:57 | ||
*/ | ||
class Solution { | ||
public: | ||
int numWaterBottles(int numBottles, int numExchange) { | ||
if(numBottles < numExchange) return numBottles; | ||
int ans = numBottles; | ||
int empty = numBottles; | ||
while(empty >= numExchange) { | ||
ans += (empty / numExchange); | ||
empty = (empty % numExchange) + (empty / numExchange); | ||
} | ||
return ans; | ||
} | ||
}; |