From 3ebc5fb653cf4722c6c59d83711cca9f8c76a6f4 Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Mon, 15 Apr 2024 21:46:27 -0700 Subject: [PATCH] twoSum done, started anagram --- Grind_70/TwoSum.py | 9 +++++++++ Grind_70/Valid_Anagram.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Grind_70/TwoSum.py create mode 100644 Grind_70/Valid_Anagram.py 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"))