Skip to content

Commit 2a31e30

Browse files
committed
new year ayyy
1 parent 705f27e commit 2a31e30

File tree

299 files changed

+4610
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+4610
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Daily-challenge/2021/Feb/01/README.md

Lines changed: 49 additions & 0 deletions

Daily-challenge/2021/Feb/01/sol.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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
7+
class Solution:
8+
def maxDepth(self, root: TreeNode) -> int:
9+
if not root:
10+
return 0
11+
12+
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))

Daily-challenge/2021/Feb/02/README.md

Lines changed: 53 additions & 0 deletions

Daily-challenge/2021/Feb/02/sol.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
8+
def __init__(self, head: ListNode):
9+
"""
10+
@param head The linked list's head.
11+
Note that the head is guaranteed to be not null, so it contains at least one node.
12+
"""
13+
self.range = []
14+
while head:
15+
self.range.append(head.val)
16+
head = head.next
17+
18+
19+
def getRandom(self) -> int:
20+
"""
21+
Returns a random node's value.
22+
"""
23+
num = int(random.random() * len(self.range))
24+
return self.range[num]
25+
26+
27+
28+
# Your Solution object will be instantiated and called as such:
29+
# obj = Solution(head)
30+
# param_1 = obj.getRandom()

Daily-challenge/2021/Feb/03/README.md

Lines changed: 48 additions & 0 deletions

Daily-challenge/2021/Feb/03/sol.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# if this null node was a left child, tail is its parent
2+
# if this null node was a right child, tail is its parent's parent
3+
if not root: return tail
4+
5+
# recursive call, traversing left while passing in the current node as tail
6+
res = self.increasingBST(root.left, root)
7+
8+
# we don't want the current node to have a left child, only a single right child
9+
root.left = None
10+
11+
# we set the current node's right child to be tail
12+
# what is tail? this part is important
13+
# if the current node is a left child, tail will be its parent
14+
# else if the current node is a right child, tail will be its parent's parent
15+
root.right = self.increasingBST(root.right, tail)
16+
17+
# throughout the whole algorithm, res is the leaf of the leftmost path in the original tree
18+
# its the smallest node and thus will be the root of the modified tree
19+
return res

Daily-challenge/2021/Feb/04/README.md

Lines changed: 56 additions & 0 deletions

Daily-challenge/2021/Feb/04/sol.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def kthFactor(self, n: int, k: int) -> int:
3+
lst = []
4+
5+
for i in range(1, n+1):
6+
if n % i == 0:
7+
lst += [i]
8+
if len(lst) < k:
9+
return -1
10+
return lst[k-1]

Daily-challenge/2021/Feb/05/README.md

Lines changed: 51 additions & 0 deletions

Daily-challenge/2021/Feb/05/sol.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
3+
i = 0
4+
lenz = len(flowerbed)
5+
count = 0
6+
7+
while i < lenz and count < n:
8+
if flowerbed[i] == 0:
9+
if i == lenz - 1:
10+
nex = 0
11+
else: nex = flowerbed[i+1]
12+
if i == 0:
13+
prev = 0
14+
else:
15+
prev = flowerbed[i-1]
16+
if nex == 0 and prev == 0:
17+
flowerbed[i] = 1
18+
count += 1
19+
20+
i += 1
21+
return count == n

0 commit comments

Comments
 (0)