diff --git a/Grind_70/TwoSum.py b/Grind_70/TwoSum.py new file mode 100644 index 0000000..22c072f --- /dev/null +++ b/Grind_70/TwoSum.py @@ -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)) \ No newline at end of file diff --git a/Grind_70/Valid_Anagram.py b/Grind_70/Valid_Anagram.py new file mode 100644 index 0000000..0378992 --- /dev/null +++ b/Grind_70/Valid_Anagram.py @@ -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"))