twoSum done, started anagram

This commit is contained in:
Jacob Delgado 2024-04-15 21:46:27 -07:00
parent 78b7c57b40
commit 3ebc5fb653
2 changed files with 26 additions and 0 deletions

9
Grind_70/TwoSum.py Normal file
View 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
View 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"))