Skip to content

Commit 46783d8

Browse files
committed
Merry Xmas!
1 parent 81e2730 commit 46783d8

File tree

5 files changed

+104
-86
lines changed

5 files changed

+104
-86
lines changed

Daily-challenge/Dec/24/README.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,6 @@ Just do while loop and convert to decimal
3030

3131
## Code
3232
```python
33-
class Solution:
34-
def calculate(self, s: str) -> int:
35-
op = '+'
36-
pre = 0; num = 0; res = 0
37-
for c in s+'+':
38-
if c.isdigit():
39-
num = 10*num + int(c)
40-
elif c in '+-*/':
41-
if op == '+':
42-
res += pre
43-
pre = num
44-
elif op == '-':
45-
res += pre
46-
pre = -num
47-
elif op == '*':
48-
pre = pre*num
49-
elif op == '/':
50-
pre = int(pre/num)
51-
num = 0
52-
op = c
53-
return res+pre
33+
Didn't do it
5434

5535
```

Daily-challenge/Dec/24/sol.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
class Solution:
2-
def calculate(self, s: str) -> int:
3-
op = '+'
4-
pre = 0; num = 0; res = 0
5-
for c in s+'+':
6-
if c.isdigit():
7-
num = 10*num + int(c)
8-
elif c in '+-*/':
9-
if op == '+':
10-
res += pre
11-
pre = num
12-
elif op == '-':
13-
res += pre
14-
pre = -num
15-
elif op == '*':
16-
pre = pre*num
17-
elif op == '/':
18-
pre = int(pre/num)
19-
num = 0
20-
op = c
21-
return res+pre
1+
DIdn't do it : (

Daily-challenge/Dec/25/README.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,64 @@
1-
# Smallest Integer Divisible by K
2-
Given a positive integer K, you need to find the length of the smallest positive integer N such that N is divisible by K, and N only contains the digit 1.
1+
# Diagonal Traverse
32

4-
Return the length of N. If there is no such N, return -1.
5-
6-
Note: N may not fit in a 64-bit signed integer.
3+
Solution
4+
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image.
75

86

97

10-
Example 1:
8+
Example:
9+
10+
Input:
11+
[
12+
[ 1, 2, 3 ],
13+
[ 4, 5, 6 ],
14+
[ 7, 8, 9 ]
15+
]
1116

12-
Input: K = 1
13-
Output: 1
14-
Explanation: The smallest answer is N = 1, which has length 1.
15-
Example 2:
17+
Output: [1,2,4,7,5,3,6,8,9]
1618

17-
Input: K = 2
18-
Output: -1
19-
Explanation: There is no such positive integer N divisible by 2.
20-
Example 3:
19+
Explanation:
2120

22-
Input: K = 3
23-
Output: 3
24-
Explanation: The smallest answer is N = 111, which has length 3.
2521

2622

27-
Constraints:
23+
Note:
2824

29-
1 <= K <= 105<br>
25+
The total number of elements of the given matrix will not exceed 10,000.<br>
3026

3127
## Idea
3228
Just do while loop and convert to decimal
3329

3430
## Code
3531
```python
3632
class Solution:
37-
def smallestRepunitDivByK(self, K: int) -> int:
38-
remainder = 0
39-
for length_N in range(1,K+1):
40-
remainder = (remainder*10+1) % K
41-
if remainder == 0:
42-
return length_N
43-
return -1
33+
def findDiagonalOrder(self, matrix: List[List[int]]) -> List[int]:
34+
resp = []
35+
if not len(matrix): return resp
36+
m = len(matrix)
37+
n = len(matrix[0])
38+
i, j = 0, 0
39+
while len(resp) < m * n:
40+
# up-right
41+
while i >= 0 and j < n:
42+
resp.append(matrix[i][j])
43+
i -= 1
44+
j += 1
45+
if j < n:
46+
i += 1
47+
else:
48+
i += 2
49+
j -= 1
50+
51+
# down-left
52+
while j >= 0 and i < m:
53+
resp.append(matrix[i][j])
54+
i += 1
55+
j -= 1
56+
if i < m:
57+
j += 1
58+
else:
59+
j += 2
60+
i -= 1
61+
62+
return resp
4463

4564
```

Daily-challenge/Dec/25/sol.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
class Solution:
2-
def smallestRepunitDivByK(self, K: int) -> int:
3-
remainder = 0
4-
for length_N in range(1,K+1):
5-
remainder = (remainder*10+1) % K
6-
if remainder == 0:
7-
return length_N
8-
return -1
2+
def findDiagonalOrder(self, matrix: List[List[int]]) -> List[int]:
3+
resp = []
4+
if not len(matrix): return resp
5+
m = len(matrix)
6+
n = len(matrix[0])
7+
i, j = 0, 0
8+
while len(resp) < m * n:
9+
# up-right
10+
while i >= 0 and j < n:
11+
resp.append(matrix[i][j])
12+
i -= 1
13+
j += 1
14+
if j < n:
15+
i += 1
16+
else:
17+
i += 2
18+
j -= 1
19+
20+
# down-left
21+
while j >= 0 and i < m:
22+
resp.append(matrix[i][j])
23+
i += 1
24+
j -= 1
25+
if i < m:
26+
j += 1
27+
else:
28+
j += 2
29+
i -= 1
30+
31+
return resp

Daily-challenge/Dec/26/README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
1-
# Longest Substring with At Least K Repeating Characters
2-
Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is less than or equal to k.
1+
# Decode Ways
2+
A message containing letters from A-Z is being encoded to numbers using the following mapping:
3+
4+
'A' -> 1
5+
'B' -> 2
6+
...
7+
'Z' -> 26
8+
Given a non-empty string containing only digits, determine the total number of ways to decode it.
9+
10+
The answer is guaranteed to fit in a 32-bit integer.
311

412

513

614
Example 1:
715

8-
Input: s = "aaabb", k = 3
9-
Output: 3
10-
Explanation: The longest substring is "aaa", as 'a' is repeated 3 times.
16+
Input: s = "12"
17+
Output: 2
18+
Explanation: It could be decoded as "AB" (1 2) or "L" (12).
1119
Example 2:
1220

13-
Input: s = "ababbc", k = 2
14-
Output: 5
15-
Explanation: The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.
21+
Input: s = "226"
22+
Output: 3
23+
Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
24+
Example 3:
25+
26+
Input: s = "0"
27+
Output: 0
28+
Explanation: There is no character that is mapped to a number starting with '0'. We cannot ignore a zero when we face it while decoding. So, each '0' should be part of "10" --> 'J' or "20" --> 'T'.
29+
Example 4:
30+
31+
Input: s = "1"
32+
Output: 1
1633

1734

1835
Constraints:
1936

20-
1 <= s.length <= 104
21-
s consists of only lowercase English letters.
22-
1 <= k <= 105<br>
37+
1 <= s.length <= 100
38+
s contains only digits and may contain leading zero(s).<br>
2339

2440
## Idea
2541
Just do while loop and convert to decimal

0 commit comments

Comments
 (0)