Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b112841

Browse files
Create 2409. Count Days Spent Together.cpp
1 parent 54d5d07 commit b112841

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int countDaysTogether(string aa, string la, string ab, string lb) {
4+
int arr[12] = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
5+
for(int i=1;i<12;i++) arr[i] = arr[i]+arr[i-1];
6+
unordered_set<int>set;
7+
int start1 = arr[stoi(aa.substr(0,2))-1]+stoi(aa.substr(3,2));
8+
int end1 = arr[stoi(la.substr(0,2))-1]+stoi(la.substr(3,2));
9+
int start2 = arr[stoi(ab.substr(0,2))-1]+stoi(ab.substr(3,2));
10+
int end2 = arr[stoi(lb.substr(0,2))-1]+stoi(lb.substr(3,2));
11+
for(int i = start1;i<=end1;i++) set.insert(i);
12+
int ans = 0;
13+
for(int i = start2;i<=end2;i++) if(set.find(i)!=set.end()) ans++;
14+
return ans;
15+
16+
}
17+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /