Skip to content

Commit d1643a3

Browse files
committed
1118 added.
1 parent 5ee7631 commit d1643a3

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(A)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(A main.cpp)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// Source : https://leetcode.com/problems/number-of-days-in-a-month/
2+
/// Author : liuyubobobo
3+
/// Time : 2019-07-13
4+
5+
#include <iostream>
6+
#include <unordered_set>
7+
8+
using namespace std;
9+
10+
11+
/// Simulation
12+
/// Time Complexity: O(1)
13+
/// Space Complexity: O(1)
14+
class Solution {
15+
public:
16+
int numberOfDays(int Y, int M) {
17+
18+
unordered_set<int> thirtyone = {1, 3, 5, 7, 8, 10, 12};
19+
if(thirtyone.count(M)) return 31;
20+
if(M == 2) return isLeapYear(Y) ? 29 : 28;
21+
return 30;
22+
}
23+
24+
private:
25+
bool isLeapYear(int Y){
26+
return (!(Y % 4) && (Y % 100)) || !(Y % 400);
27+
}
28+
};
29+
30+
31+
int main() {
32+
33+
return 0;
34+
}

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,6 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
761761
| 1109 | [Corporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings/) | [] | [C++](1109-Corporate-Flight-Bookings/cpp-1009/) | | |
762762
| 1110 | [Delete Nodes And Return Forest](https://leetcode.com/problems/delete-nodes-and-return-forest/) | [] | [C++](1110-Delete-Nodes-And-Return-Forest/cpp-1110/) | | |
763763
| 1111 | [Maximum Nesting Depth of Two Valid Parentheses Strings](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/) | [] | [C++](1111-Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/cpp-1111/) | | |
764-
| | | | | | |
764+
| | | | | | |
765+
| 1118 | [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month/) | [] | [C++](1118-Number-of-Days-in-a-Month/cpp-1118/) | | |
766+
| | | | | | |

0 commit comments

Comments
 (0)