Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Problem 1:
## Given an array of strings, group anagrams together.

class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
final_dict = {}

for str_vals in strs:
a = [x for x in str_vals]
a.sort()
a = ''.join(a)
if a not in final_dict:
final_dict[a]=[str_vals]
else:
final_dict[a].append(str_vals)
return list(final_dict.values())
22 changes: 22 additions & 0 deletions problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Problem 2:
#Given two strings s and t, determine if they are isomorphic.

class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
map_dict = {

}
check_set = set()
if len(s) != len(t):
return False
for i in range(len(s)):
if s[i] not in map_dict:
if t[i] not in check_set:
map_dict[s[i]]=t[i]
check_set.add(t[i])
else:
return False
else:
if map_dict[s[i]] != t[i]:
return False
return True
22 changes: 22 additions & 0 deletions problem3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://leetcode.com/problems/word-pattern/

class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
my_hash = {

}
my_set = set()
if len([x for x in pattern]) != len(s.split(' ')):
return False
for s_map,w_map in zip([x for x in pattern],s.split(' ')):
if s_map in my_hash:
if my_hash[s_map] != w_map:
return False
else:
if w_map in my_set:
return False
else:
my_hash[s_map] = w_map
my_set.add(w_map)
return True