Skip to content

Commit 2fd9769

Browse files
committed
add mock problems
- google oa 202005160200 - facebook phone 202005160237
1 parent b5d1846 commit 2fd9769

File tree

19 files changed

+116
-0
lines changed

19 files changed

+116
-0
lines changed
13 KB
Binary file not shown.
83.1 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
3+
class Solution:
4+
def isPalindrome(self, s: str) -> bool:
5+
s = re.sub('[^a-z0-9]', '', s.lower())
6+
n = len(s)
7+
i = 0
8+
while i < n - 1 - i:
9+
if s[i] != s[n - 1 - i]:
10+
return False
11+
i += 1
12+
return True
14.1 KB
Binary file not shown.
107 KB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def validPalindrome(self, s: str) -> bool:
3+
def isPal(s, i, j):
4+
while i < j:
5+
if s[i] != s[j]:
6+
return False, i, j
7+
i += 1
8+
j -= 1
9+
return True, -1, -1
10+
11+
ret, i, j = isPal(s, 0, len(s) - 1)
12+
if ret:
13+
return True
14+
ret, _, _ = isPal(s, i + 1, j)
15+
if ret:
16+
return True
17+
ret, _, _ = isPal(s, i, j - 1)
18+
if ret:
19+
return True
20+
return False
13.4 KB
Binary file not shown.
122 KB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution:
2+
def addOperators(self, num: str, target: int) -> List[str]:
3+
if len(num) == 0:
4+
return []
5+
6+
ops = {}
7+
ops['+'] = lambda x, y: x + y
8+
ops['-'] = lambda x, y: x - y
9+
ops['*'] = lambda x, y: x * y
10+
11+
res = []
12+
def dfs(idx, arr, op):
13+
nonlocal res
14+
15+
if idx == len(num):
16+
expr = ''.join(arr)
17+
n = eval(expr)
18+
if n == target:
19+
res.append(expr)
20+
return
21+
if op:
22+
for c in ops:
23+
arr.append(c)
24+
dfs(idx, arr, not op)
25+
arr.pop()
26+
else:
27+
nr = len(num) if num[idx] != '0' else idx + 1
28+
for i in range(idx, nr):
29+
x = num[idx: i + 1]
30+
arr.append(x)
31+
dfs(i + 1, arr, not op)
32+
arr.pop()
33+
dfs(0, [], False)
34+
return res
15.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)