Skip to content

Commit 28f6ed6

Browse files
committed
16/12/2020
1 parent 6dc3568 commit 28f6ed6

File tree

4 files changed

+43
-61
lines changed

4 files changed

+43
-61
lines changed

Daily-challenge/Dec/14/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ s contains only lowercase English letters.<br>
2525
## Code
2626
```python
2727
class Solution:
28-
def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:
29-
return ceil(log(buckets)/log(minutesToTest//minutesToDie + 1))
28+
def partition(self, s: str) -> List[List[str]]:
29+
dp = [[] for _ in range(len(s) + 1)]
30+
dp[-1] = [[]]
31+
for i in range(len(s) - 1, -1, -1):
32+
for j in range(i + 1, len(s) + 1):
33+
if s[i:j] == s[i:j][::-1]:
34+
for each in dp[j]:
35+
dp[i].append([s[i:j]] + each)
36+
return dp[0]
3037

3138
```
3239

Daily-challenge/Dec/14/sol.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
class Solution:
2-
def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:
3-
return ceil(log(buckets)/log(minutesToTest//minutesToDie + 1))
2+
def partition(self, s: str) -> List[List[str]]:
3+
dp = [[] for _ in range(len(s) + 1)]
4+
dp[-1] = [[]]
5+
for i in range(len(s) - 1, -1, -1):
6+
for j in range(i + 1, len(s) + 1):
7+
if s[i:j] == s[i:j][::-1]:
8+
for each in dp[j]:
9+
dp[i].append([s[i:j]] + each)
10+
return dp[0]

Daily-challenge/Dec/15/README.md

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,39 @@
1-
# Range Sum of BST
2-
Given the root node of a binary search tree, return the sum of values of all nodes with a value in the range [low, high].
1+
# Squares of a Sorted Array
2+
3+
Solution
4+
Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
35

46

57

68
Example 1:
79

8-
9-
Input: root = [10,5,15,3,7,null,18], low = 7, high = 15
10-
Output: 32
10+
Input: nums = [-4,-1,0,3,10]
11+
Output: [0,1,9,16,100]
12+
Explanation: After squaring, the array becomes [16,1,0,9,100].
13+
After sorting, it becomes [0,1,9,16,100].
1114
Example 2:
1215

13-
14-
Input: root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10
15-
Output: 23
16+
Input: nums = [-7,-3,2,3,11]
17+
Output: [4,9,9,49,121]
1618

1719

1820
Constraints:
1921

20-
The number of nodes in the tree is in the range [1, 2 * 104].
21-
1 <= Node.val <= 105
22-
1 <= low <= high <= 105
23-
All Node.val are unique.<br>
22+
1 <= nums.length <= 104
23+
-104 <= nums[i] <= 104
24+
nums is sorted in non-decreasing order.<br>
2425

2526
## Idea
2627

2728
## Code
2829
```python
29-
# Definition for a binary tree node.
30-
# class TreeNode:
31-
# def __init__(self, val=0, left=None, right=None):
32-
# self.val = val
33-
# self.left = left
34-
# self.right = right
3530
class Solution:
36-
def rangeSumBST(self, root: TreeNode, low: int, high: int) -> int:
31+
def sortedSquares(self, nums: List[int]) -> List[int]:
32+
lst = []
3733

38-
global res
39-
res = 0
40-
41-
def tran(root):
42-
global res
43-
if root == None: return
44-
# print(root.val)
45-
if low <= root.val <= high:
46-
res += root.val
47-
if low < root.val:
48-
tran(root.left)
49-
if root.val < high:
50-
tran(root.right)
51-
tran(root)
52-
return res
53-
34+
for i in nums:
35+
lst += [i**2]
36+
37+
return sorted(lst)
5438
```
5539

Daily-challenge/Dec/15/sol.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
1-
# Definition for a binary tree node.
2-
# class TreeNode:
3-
# def __init__(self, val=0, left=None, right=None):
4-
# self.val = val
5-
# self.left = left
6-
# self.right = right
71
class Solution:
8-
def rangeSumBST(self, root: TreeNode, low: int, high: int) -> int:
2+
def sortedSquares(self, nums: List[int]) -> List[int]:
3+
lst = []
94

10-
global res
11-
res = 0
12-
13-
def tran(root):
14-
global res
15-
if root == None: return
16-
# print(root.val)
17-
if low <= root.val <= high:
18-
res += root.val
19-
if low < root.val:
20-
tran(root.left)
21-
if root.val < high:
22-
tran(root.right)
23-
tran(root)
24-
return res
5+
for i in nums:
6+
lst += [i**2]
7+
8+
return sorted(lst)

0 commit comments

Comments
 (0)