|
| 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