Skip to content

Commit 88fb978

Browse files
authored
Merge pull request #1501 from ivan1016017/december30
adding algo
2 parents d6750fd + 0d227a5 commit 88fb978

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def twoSum(self, nums: List[int], target: int) -> List[int]:
6+
7+
answer = dict()
8+
9+
for k, v in enumerate(nums):
10+
11+
if v in answer:
12+
return [answer[v], k]
13+
else:
14+
answer[target - v] = k
15+
16+
return []
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
from typing import List, Union, Collection, Mapping, Optional
3+
from abc import ABC, abstractmethod
4+
import re
5+
6+
class Solution:
7+
def isPalindrome(self, s: str) -> bool:
8+
9+
# To lowercase
10+
s = s.lower()
11+
12+
# Remove non-alphanumeric characters
13+
s = re.sub(pattern=r'[^a-zA-Z0-9]', repl='', string=s)
14+
15+
# Determine if s is palindrome or not
16+
len_s = len(s)
17+
18+
for i in range(len_s//2):
19+
20+
if s[i] != s[len_s - 1 - i]:
21+
return False
22+
23+
return True

0 commit comments

Comments
 (0)