-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1021 from Soohyeun/main
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from collections import defaultdict | ||
|
||
|
||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
if len(s) != len(t): | ||
return False | ||
|
||
seen = defaultdict(int) | ||
for i in range(len(s)): | ||
seen[s[i]] += 1 | ||
seen[t[i]] -= 1 | ||
if seen[s[i]] == 0: | ||
del seen[s[i]] | ||
if seen[t[i]] == 0: | ||
del seen[t[i]] | ||
|
||
return True if not seen else False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Solution: | ||
def twoSum(self, nums: List[int], target: int) -> List[int]: | ||
seen = dict() | ||
for index, num in enumerate(nums): | ||
rest = target - num | ||
if rest in seen.keys(): | ||
return [seen[rest], index] | ||
seen[num] = index | ||
return -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Solution: | ||
def hasDuplicate(self, nums: List[int]) -> bool: | ||
set_num = set(nums) | ||
|
||
return False if len(set_num) == len(nums) else True |