Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 56025e3

Browse files
python: add problem 63 and unittest
1 parent 5c93988 commit 56025e3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Python/sln_1_100/solution_61_70.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from typing import *
23
from common_utils import *
34

45

@@ -33,6 +34,34 @@ def rotateRight(self, head, k):
3334
last_node.next = head
3435
return new_head
3536

37+
def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
38+
"""
39+
63
40+
:param obstacleGrid:
41+
:return:
42+
"""
43+
if not obstacleGrid or not obstacleGrid[0]:
44+
return 0
45+
46+
horizon_len = len(obstacleGrid) - 1
47+
vertical_len = len(obstacleGrid[0]) - 1
48+
count = [0]
49+
50+
def is_valid(horizon_idx, vertical_idx):
51+
if obstacleGrid[horizon_idx][vertical_idx] != 0:
52+
return
53+
if horizon_idx == horizon_len and vertical_idx == vertical_len:
54+
count[0] += 1
55+
return
56+
57+
if horizon_idx < horizon_len:
58+
is_valid(horizon_idx + 1, vertical_idx)
59+
if vertical_idx < vertical_len:
60+
is_valid(horizon_idx, vertical_idx + 1)
61+
62+
is_valid(0, 0)
63+
return count[0]
64+
3665
def addBinary(self, a, b):
3766
"""
3867
67

Python/sln_1_100/test_solution_61_70.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ def test_rotate_right(self):
2626
def test_addBinary(self):
2727
ret = self.sln.addBinary('11', '1')
2828
print(ret)
29+
30+
def test_uniquePathsWithObstacles(self):
31+
matrix = [
32+
[0, 0, 0],
33+
[0, 1, 0],
34+
[0, 0, 0]
35+
]
36+
ret = self.sln.uniquePathsWithObstacles(matrix)
37+
print(ret)

0 commit comments

Comments
 (0)