Skip to content

Commit e2b859c

Browse files
committed
07/12/2020
1 parent 2435c82 commit e2b859c

File tree

3 files changed

+67
-43
lines changed

3 files changed

+67
-43
lines changed

Daily-challenge/Dec/06/README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,31 @@ yea ill ttyl
3939
## Code
4040
```python
4141

42-
# Definition for singly-linked list.
43-
# class ListNode:
44-
# def __init__(self, val=0, next=None):
45-
# self.val = val
46-
# self.next = next
42+
"""
43+
# Definition for a Node.
44+
class Node:
45+
def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):
46+
self.val = val
47+
self.left = left
48+
self.right = right
49+
self.next = next
50+
"""
51+
4752
class Solution:
48-
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
49-
s1, s2 = [], []
50-
while l1:
51-
s1.append(l1.val)
52-
l1 = l1.next
53-
54-
while l2:
55-
s2.append(l2.val)
56-
l2 = l2.next
57-
58-
carry = 0
59-
head = ListNode(0)
60-
while s1 or s2 or carry:
61-
if s1:
62-
carry += s1.pop()
63-
if s2:
64-
carry += s2.pop()
65-
carry, val = divmod(carry, 10)
66-
head.next, head.next.next = ListNode(val), head.next
67-
return head.next
53+
def connect(self, root: 'Node') -> 'Node':
54+
node = root
55+
while node:
56+
cur = dummy = Node(0)
57+
while node:
58+
if node.left:
59+
cur.next = node.left
60+
cur = cur.next
61+
62+
if node.right:
63+
cur.next = node.right
64+
cur = cur.next
65+
66+
node = node.next
67+
node = dummy.next
68+
return root
6869
```

Daily-challenge/Dec/06/sol.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
"""
2+
# Definition for a Node.
3+
class Node:
4+
def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):
5+
self.val = val
6+
self.left = left
7+
self.right = right
8+
self.next = next
9+
"""
10+
111
class Solution:
2-
def minCostToMoveChips(self, position: List[int]) -> int:
3-
eve = 0
4-
odd = 0
5-
for i in position:
6-
if i % 2 == 0:
7-
eve += 1
8-
else:
9-
odd += 1
10-
11-
return min(eve, odd)
12+
def connect(self, root: 'Node') -> 'Node':
13+
node = root
14+
while node:
15+
cur = dummy = Node(0)
16+
while node:
17+
if node.left:
18+
cur.next = node.left
19+
cur = cur.next
20+
21+
if node.right:
22+
cur.next = node.right
23+
cur = cur.next
24+
25+
node = node.next
26+
node = dummy.next
27+
return root

Daily-challenge/Dec/07/README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
# Add Two Numbers II
2-
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
1+
# Spiral Matrix II
2+
Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.
33

4-
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
4+
![idk](https://assets.leetcode.com/uploads/2020/11/13/spiraln.jpg)
55

6-
Follow up:
7-
What if you cannot modify the input lists? In other words, reversing the lists is not allowed.
6+
Example 1:
87

9-
Example:
108

11-
Input: (7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)
12-
Output: 7 -> 8 -> 0 -> 7<br>
9+
Input: n = 3
10+
Output: [[1,2,3],[8,9,4],[7,6,5]]
11+
Example 2:
12+
13+
Input: n = 1
14+
Output: [[1]]
15+
16+
17+
Constraints:
18+
19+
1 <= n <= 20<br>
1320

1421
## Idea
1522

0 commit comments

Comments
 (0)