Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e276d3

Browse files
Update
1 parent ff9ea06 commit 8e276d3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎DSA_RoadMap/03_TwoSum.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import List
22

3+
# ---------------------- Solution 1 -----------------------
4+
35
# class Solution:
46
# def twoSum(self, nums: List[int], target: int) -> List[int]:
57
# n = len(nums)
@@ -10,6 +12,8 @@
1012
# return [i, num2]
1113
# # raise ValueError("No solution found")
1214

15+
# ---------------------- Solution 2 -----------------------
16+
1317

1418
class Solution:
1519
def twoSum(self, nums: List[int], target: int) -> List[int]:

‎DSA_RoadMap/04_Group_Anagrams.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
3+
# ---------------------- Solution 1 -----------------------
4+
5+
class Solution:
6+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
7+
ls = []*len(strs)
8+
for i in range(len(strs)):
9+
sls = sorted(strs[i])
10+
for j in range(len(strs)):
11+
if sls == sorted(strs[j]):
12+
ls.append(ls[j]+ [strs[i]])
13+
return [x for x in ls if len(x)>0 ]
14+
15+
# Testing the solution
16+
17+
18+
19+
20+
21+
strs = ["eat","tea","tan","ate","nat","bat"]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /