twoSum done, started anagram
This commit is contained in:
parent
78b7c57b40
commit
3ebc5fb653
9
Grind_70/TwoSum.py
Normal file
9
Grind_70/TwoSum.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
def twoSum(nums, target):
|
||||||
|
index = {} # create a dictionary
|
||||||
|
for i in range(len(nums)):
|
||||||
|
if (target-nums[i]) in index: # pass each value until its' matching pair is found
|
||||||
|
return [index[target-nums[i]], i]
|
||||||
|
index[nums[i]] = i # store values of non-matching pair
|
||||||
|
|
||||||
|
print(twoSum([2,7,11,15], 9))
|
||||||
|
# print(twoSum([3,3], 6))
|
||||||
17
Grind_70/Valid_Anagram.py
Normal file
17
Grind_70/Valid_Anagram.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Given two strings s and t, return true if t is an anagram of s, and false otherwise.
|
||||||
|
|
||||||
|
# An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
|
||||||
|
|
||||||
|
class Solution(object):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
def isAnagram(self, s, t):
|
||||||
|
"""
|
||||||
|
:type s: str
|
||||||
|
:type t: str
|
||||||
|
:rtype: bool
|
||||||
|
"""
|
||||||
|
return 0
|
||||||
|
|
||||||
|
sol = Solution()
|
||||||
|
print(sol.isAnagram("anagram", "nagram"))
|
||||||
Loading…
Reference in New Issue
Block a user