Skip to content

Commit 11d20bd

Browse files
committed
update 3280
1 parent bc0fc10 commit 11d20bd

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ This is an open-source project that is continually updated
1212

1313
**2023:** 177 problems
1414

15-
**2024:** 256 problems
15+
**2024:** 257 problems
1616

17-
**Total:** 433 problems
17+
**Total:** 434 problems
1818

19-
**Updated:** 2024-09-11 15:56:11
19+
**Updated:** 2024-09-12 14:45:16
2020

2121
## 链接/Links
2222

@@ -88,7 +88,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
8888

8989
## Math
9090

91-
| Update | Problem(18) | Solution | Tag | Time | Space | Ref |
91+
| Update | Problem(19) | Solution | Tag | Time | Space | Ref |
9292
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
9393
| 2024-06 | [Leetcode-263. Ugly Number](https://leetcode.com/problems/ugly-number/description/) | [c++](./leetcode/263.ugly-number.cpp), [python3](./leetcode/263.ugly-number.py) | Math | O\(k\) | O\(1\) | - |
9494
| 2024-06 | [Leetcode-633. Sum Of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/description/) | [c++](./leetcode/633.sum-of-square-numbers.cpp), [python3](./leetcode/633.sum-of-square-numbers.py) | Math | O\(N\) | O\(1\) | - |
@@ -108,6 +108,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
108108
| 2024-08 | [Leetcode-50. Powx N](https://leetcode.com/problems/powx-n/description/) | [c++](./leetcode/50.powx-n.cpp), [python3](./leetcode/50.powx-n.py) | Math | O\(logN\) | O\(1\) | - |
109109
| 2024-09 | [Leetcode-3274. Check If Two Chessboard Squares Have The Same Color](https://leetcode.com/problems/check-if-two-chessboard-squares-have-the-same-color/description/) | [c++](./leetcode/3274.check-if-two-chessboard-squares-have-the-same-color.cpp), [python3](./leetcode/3274.check-if-two-chessboard-squares-have-the-same-color.py) | Math | O\(1\) | O\(1\) | - |
110110
| 2024-09 | [Leetcode-367. Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square/description/) | [c++](./leetcode/367.valid-perfect-square.cpp), [python3](./leetcode/367.valid-perfect-square.py) | Math | O\(logN\) | O\(1\) | - |
111+
| 2024-09 | [Leetcode-3280. Convert Date To Binary](https://leetcode.com/problems/convert-date-to-binary/description/) | [c++](./leetcode/3280.convert-date-to-binary.cpp), [python3](./leetcode/3280.convert-date-to-binary.py) | Math | O\(1\) | O\(1\) | - |
111112

112113
## Probability
113114

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Tag: Math, String
2+
// Time: O(1)
3+
// Space: O(1)
4+
// Ref: -
5+
// Note: -
6+
7+
// You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format.
8+
// date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format.
9+
// Return the binary representation of date.
10+
//  
11+
// Example 1:
12+
//
13+
// Input: date = "2080-02-29"
14+
// Output: "100000100000-10-11101"
15+
// Explanation:
16+
// 100000100000, 10, and 11101 are the binary representations of 2080, 02, and 29 respectively.
17+
//
18+
// Example 2:
19+
//
20+
// Input: date = "1900-01-01"
21+
// Output: "11101101100-1-1"
22+
// Explanation:
23+
// 11101101100, 1, and 1 are the binary representations of 1900, 1, and 1 respectively.
24+
//
25+
//  
26+
// Constraints:
27+
//
28+
// date.length == 10
29+
// date[4] == date[7] == '-', and all other date[i]'s are digits.
30+
// The input is generated such that date represents a valid Gregorian calendar date between Jan 1st, 1900 and Dec 31st, 2100 (both inclusive).
31+
//
32+
//
33+
34+
class Solution {
35+
public:
36+
string convertDateToBinary(string date) {
37+
int number = 0;
38+
string res = "";
39+
for (auto ch: date) {
40+
if (ch == '-') {
41+
res += convert(number) + '-';
42+
number = 0;
43+
} else {
44+
number = number * 10 + ch - '0';
45+
}
46+
}
47+
return res + convert(number);
48+
}
49+
50+
string convert(int number) {
51+
string res = "";
52+
while (number) {
53+
res = to_string(number & 1) + res;
54+
number = number >> 1;
55+
}
56+
return res;
57+
}
58+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Tag: Math, String
2+
# Time: O(1)
3+
# Space: O(1)
4+
# Ref: -
5+
# Note: -
6+
7+
# You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format.
8+
# date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format.
9+
# Return the binary representation of date.
10+
#  
11+
# Example 1:
12+
#
13+
# Input: date = "2080-02-29"
14+
# Output: "100000100000-10-11101"
15+
# Explanation:
16+
# 100000100000, 10, and 11101 are the binary representations of 2080, 02, and 29 respectively.
17+
#
18+
# Example 2:
19+
#
20+
# Input: date = "1900-01-01"
21+
# Output: "11101101100-1-1"
22+
# Explanation:
23+
# 11101101100, 1, and 1 are the binary representations of 1900, 1, and 1 respectively.
24+
#
25+
#  
26+
# Constraints:
27+
#
28+
# date.length == 10
29+
# date[4] == date[7] == '-', and all other date[i]'s are digits.
30+
# The input is generated such that date represents a valid Gregorian calendar date between Jan 1st, 1900 and Dec 31st, 2100 (both inclusive).
31+
#
32+
#
33+
34+
class Solution:
35+
def convertDateToBinary(self, date: str) -> str:
36+
return "-".join([self.convert(num) for num in date.split('-')])
37+
38+
def convert(self, number: str) -> str:
39+
number = int(number)
40+
res = ''
41+
while number > 0:
42+
res = str(number & 1) + res
43+
number = number >> 1
44+
45+
return res

0 commit comments

Comments
 (0)