[go: nahoru, domu]

Skip to content

Commit

Permalink
update easy
Browse files Browse the repository at this point in the history
  • Loading branch information
lzyrapx committed Jul 25, 2020
1 parent 1bc7590 commit ce599c6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
26 changes: 26 additions & 0 deletions LeetCode/Easy/1507.cpp
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;
}
};
22 changes: 22 additions & 0 deletions LeetCode/Easy/1512.cpp
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;
}
};
18 changes: 18 additions & 0 deletions LeetCode/Easy/1518.cpp
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;
}
};

0 comments on commit ce599c6

Please sign in to comment.