From a7e5c741c8db8d2065b2e8fc6d6384aaf93a36b8 Mon Sep 17 00:00:00 2001 From: AldythNahak Date: Sat, 21 Jun 2025 09:49:04 -0600 Subject: [PATCH] clean folder --- ...dex_of_the_first_occurrence_in_a_string.py | 12 ---- Easy/longest_common_prefix.py | 41 ------------- Easy/palindrome_number.py | 12 ---- Easy/remove_duplicate_from_sorted_arrays.py | 10 ---- Easy/remove_element.py | 12 ---- Easy/roman_to_integer.py | 29 --------- Easy/search_insert_position.py | 17 ------ Easy/two_sum.py | 19 ------ Easy/valid_parentheses.py | 43 -------------- Hard/longest_valid_parentheses.py | 30 ---------- Hard/median_of_two_sorted_arrays.py | 27 --------- Hard/regular_expression_matching.py | 18 ------ ...bstring_with_concatenation_of_all_words.py | 59 ------------------- Medium/add_two_numbers.py | 32 ---------- Medium/divide_to_integers.py | 34 ----------- ...ast_position_of_element_in_sorted_array.py | 23 -------- Medium/integer_to_roman.py | 28 --------- Medium/longest_palindrome_substring.py | 34 ----------- ...subtstring_without_repeating_characters.py | 30 ---------- Medium/reverse_integer.py | 24 -------- Medium/string_to_integer_atoi.py | 34 ----------- Medium/three_sum.py | 53 ----------------- Medium/three_sum_closest.py | 40 ------------- Medium/zigzag_conversion.py | 34 ----------- 24 files changed, 695 deletions(-) delete mode 100644 Easy/find_the_index_of_the_first_occurrence_in_a_string.py delete mode 100644 Easy/longest_common_prefix.py delete mode 100644 Easy/palindrome_number.py delete mode 100644 Easy/remove_duplicate_from_sorted_arrays.py delete mode 100644 Easy/remove_element.py delete mode 100644 Easy/roman_to_integer.py delete mode 100644 Easy/search_insert_position.py delete mode 100644 Easy/two_sum.py delete mode 100644 Easy/valid_parentheses.py delete mode 100644 Hard/longest_valid_parentheses.py delete mode 100644 Hard/median_of_two_sorted_arrays.py delete mode 100644 Hard/regular_expression_matching.py delete mode 100644 Hard/substring_with_concatenation_of_all_words.py delete mode 100644 Medium/add_two_numbers.py delete mode 100644 Medium/divide_to_integers.py delete mode 100644 Medium/find_first_and_last_position_of_element_in_sorted_array.py delete mode 100644 Medium/integer_to_roman.py delete mode 100644 Medium/longest_palindrome_substring.py delete mode 100644 Medium/longest_subtstring_without_repeating_characters.py delete mode 100644 Medium/reverse_integer.py delete mode 100644 Medium/string_to_integer_atoi.py delete mode 100644 Medium/three_sum.py delete mode 100644 Medium/three_sum_closest.py delete mode 100644 Medium/zigzag_conversion.py diff --git a/Easy/find_the_index_of_the_first_occurrence_in_a_string.py b/Easy/find_the_index_of_the_first_occurrence_in_a_string.py deleted file mode 100644 index 5297e9f..0000000 --- a/Easy/find_the_index_of_the_first_occurrence_in_a_string.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def strStr(self, haystack, needle): - """ - :type haystack: str - :type needle: str - :rtype: int - """ - return str(haystack).find(needle) - - -print(Solution().strStr("sadbutsad", "sad")) -print(Solution().strStr("leetcode", "leeto")) \ No newline at end of file diff --git a/Easy/longest_common_prefix.py b/Easy/longest_common_prefix.py deleted file mode 100644 index 45f1543..0000000 --- a/Easy/longest_common_prefix.py +++ /dev/null @@ -1,41 +0,0 @@ -class Solution(object): - def longestCommonPrefix(self, strs): - """ - :type strs: List[str] - :rtype: str - """ - if len(strs) == 0 or len(strs) > 200: - return "" - - def sortByLen(s): - return len(s) - - strs.sort(key=sortByLen) - lenShortText = len(strs[0]) - collectPrefix = [] - - for i in range(lenShortText): - if len(collectPrefix) == i: - collectPrefix.append(strs[0][i]) - - if i > len(collectPrefix) or len(collectPrefix) == 0: - break - - for _, text in enumerate(strs): - if not text: - continue - - if text[i] != collectPrefix[i]: - if len(collectPrefix) > 0: - collectPrefix.pop() - break - - return "".join(collectPrefix) - -print(Solution().longestCommonPrefix(["flower","flow","flight"])) #fl -print(Solution().longestCommonPrefix(["flower","flow",""])) #fl -print(Solution().longestCommonPrefix(["flower","flower","flower","flower"])) #flower -print(Solution().longestCommonPrefix(["ab", "a"])) #a -print(Solution().longestCommonPrefix(["", ""])) # -print(Solution().longestCommonPrefix(["a"])) #a - diff --git a/Easy/palindrome_number.py b/Easy/palindrome_number.py deleted file mode 100644 index 9d9c967..0000000 --- a/Easy/palindrome_number.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def isPalindrome(self, x): - """ - :type x: int - :rtype: bool - """ - strX = str(x) - return strX == strX[::-1] - -print(Solution().isPalindrome(121)) #true -print(Solution().isPalindrome(-121)) #false -print(Solution().isPalindrome(10)) #false \ No newline at end of file diff --git a/Easy/remove_duplicate_from_sorted_arrays.py b/Easy/remove_duplicate_from_sorted_arrays.py deleted file mode 100644 index 3e58524..0000000 --- a/Easy/remove_duplicate_from_sorted_arrays.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def removeDuplicates(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - return len(list(set(nums))) - -print(Solution().removeDuplicates([0,0,1,1,1,2,2,3,3,4])) -print(Solution().removeDuplicates([1,1,2])) \ No newline at end of file diff --git a/Easy/remove_element.py b/Easy/remove_element.py deleted file mode 100644 index 4cec6d1..0000000 --- a/Easy/remove_element.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def removeElement(self, nums, val): - """ - :type nums: List[int] - :type val: int - :rtype: int - """ - return len([v for v in nums if v != val]) - -print(Solution().removeElement([3, 2, 2, 3], 3)) -print(Solution().removeElement([0, 1, 2, 2, 3, 0, 4, 2], 2)) - \ No newline at end of file diff --git a/Easy/roman_to_integer.py b/Easy/roman_to_integer.py deleted file mode 100644 index a45c486..0000000 --- a/Easy/roman_to_integer.py +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def romanToInt(self, s): - """ - :type s: str - :rtype: int - """ - symbolMap = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} - s = str(s).upper() - total = 0 - - for i, c in enumerate(s): - if c not in symbolMap: - break - - if i > 0: - if (c == "V" or c == "X") and s[i-1] == "I": - total -= 2 - - if (c == "L" or c == "C") and s[i-1] == "X": - total -= 20 - - if (c == "D" or c == "M") and s[i-1] == "C": - total -= 200 - - total += symbolMap.get(c) - - return total - -print(Solution().romanToInt("MCMXCIV")) \ No newline at end of file diff --git a/Easy/search_insert_position.py b/Easy/search_insert_position.py deleted file mode 100644 index 81850fb..0000000 --- a/Easy/search_insert_position.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def searchInsert(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: int - """ - index = 0 - for i, n in enumerate(nums): - if n >= target: - index = i - break - - if len(nums) > 0 and index == 0 and nums[len(nums) - 1] < target: - return len(nums) - - return index \ No newline at end of file diff --git a/Easy/two_sum.py b/Easy/two_sum.py deleted file mode 100644 index 00933f9..0000000 --- a/Easy/two_sum.py +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def twoSum(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - lists = {} - for i, n in enumerate(nums): - s = target - n - if s in lists: - return [lists[s], i] - - lists[n] = i - -print(Solution().twoSum([2,7,11,15], 9)) #[0, 1] -print(Solution().twoSum([3,2,4], 6)) #[1, 2] -print(Solution().twoSum([3,3], 6)) #[0, 1] -print(Solution().twoSum([-3,4,3,90], 0)) #[0, 2] diff --git a/Easy/valid_parentheses.py b/Easy/valid_parentheses.py deleted file mode 100644 index b1f997d..0000000 --- a/Easy/valid_parentheses.py +++ /dev/null @@ -1,43 +0,0 @@ -class Solution(object): - def isValid(self, s): - """ - :type s: str - :rtype: bool - """ - - if len(s)%2 != 0 or len(s) > 10000: - return False - - mapParentheses = {"(": ")","[": "]", "{": "}"} - collectParentheses = [] - - for i, c in enumerate(s): - if i == 0 and c in mapParentheses.values(): - return False - - if c not in mapParentheses.keys() and c not in mapParentheses.values(): - return False - - if len(collectParentheses) == 0 and c in mapParentheses.values(): - return False - - if mapParentheses.__contains__(c): - collectParentheses.append(c) - continue - - lastCheck = collectParentheses[-1] - if mapParentheses.get(lastCheck) == c: - collectParentheses.pop() - continue - else: - return False - - return len(collectParentheses) == 0 - -print(Solution().isValid("(]")) #false -print(Solution().isValid("()[]{}")) #true -print(Solution().isValid("([])")) #true -print(Solution().isValid("(}{)")) #false -print(Solution().isValid("([{}])")) #true -print(Solution().isValid("(){}}{")) #false -print(Solution().isValid("(([]){})")) #true \ No newline at end of file diff --git a/Hard/longest_valid_parentheses.py b/Hard/longest_valid_parentheses.py deleted file mode 100644 index c9efaf6..0000000 --- a/Hard/longest_valid_parentheses.py +++ /dev/null @@ -1,30 +0,0 @@ -class Solution(object): - def longestValidParentheses(self, s): - """ - :type s: str - :rtype: int - """ - countValidParentheses = 0 - storeIndex = [-1] - - for i, c in enumerate(s): - if c == "(": - storeIndex.append(i) - else: - storeIndex.pop() - - if len(storeIndex) == 0: - storeIndex.append(i) - else: - countValidParentheses = max(countValidParentheses, i - storeIndex[-1]) - - return countValidParentheses - -print(Solution().longestValidParentheses("(()")) #2 -print(Solution().longestValidParentheses(")()())")) #4 -print(Solution().longestValidParentheses("")) #0 -print(Solution().longestValidParentheses("()(()")) #2 -print(Solution().longestValidParentheses("()(())")) #6 -print(Solution().longestValidParentheses("()")) #6 - - diff --git a/Hard/median_of_two_sorted_arrays.py b/Hard/median_of_two_sorted_arrays.py deleted file mode 100644 index 1092cbd..0000000 --- a/Hard/median_of_two_sorted_arrays.py +++ /dev/null @@ -1,27 +0,0 @@ -class Solution(object): - def findMedianSortedArrays(self, nums1, nums2): - """ - :type nums1: List[int] - :type nums2: List[int] - :rtype: float - """ - if len(nums1) > 1000 or len(nums2) > 1000: - return None - - joinArr = sorted(nums1 + nums2) - lenJoinArr = len(joinArr) - - if lenJoinArr == 0 or lenJoinArr > 2000: - return None - - mid = lenJoinArr // 2 - if lenJoinArr % 2 == 1: - return float(joinArr[mid]) - else: - return (joinArr[mid - 1] + joinArr[mid]) / 2.0 - - - - -print(Solution().findMedianSortedArrays([1,3], [2])) -print(Solution().findMedianSortedArrays([1,2], [3,4])) \ No newline at end of file diff --git a/Hard/regular_expression_matching.py b/Hard/regular_expression_matching.py deleted file mode 100644 index 3e5ea45..0000000 --- a/Hard/regular_expression_matching.py +++ /dev/null @@ -1,18 +0,0 @@ -import re - -class Solution(object): - def isMatch(self, s, p): - """ - :type s: str - :type p: str - :rtype: bool - """ - - if len(s) == 0 or len(s) > 20 or len(p) == 0 or len(p) > 20: - return False - - return bool(re.search("^"+p+"$", s)) - -print(Solution().isMatch("aa", "a")) #False -print(Solution().isMatch("aa", "a*")) #True -print(Solution().isMatch("ab", ".*")) #True \ No newline at end of file diff --git a/Hard/substring_with_concatenation_of_all_words.py b/Hard/substring_with_concatenation_of_all_words.py deleted file mode 100644 index 0e5d474..0000000 --- a/Hard/substring_with_concatenation_of_all_words.py +++ /dev/null @@ -1,59 +0,0 @@ -from collections import Counter - -class Solution(object): - def findSubstring(self, s, words): - """ - :type s: str - :type words: List[str] - :rtype: List[int] - """ - # Simple but Limited time out - # permutations = itertools.permutations(words) - # collectKeywords = list(set(["".join(p) for p in permutations])) - # indexMatch = sorted([i for k in collectKeywords for i in range(len(s)) if s.startswith(k, i)]) - # return indexMatch - - if not words or len(words) > 5000: - return [] - - if not s or len(s) > 10**4: - return [] - - lenText = len(s) - lenKeyword = sum(len(k) for k in words) - - if lenText < lenKeyword: - return [] - - totalKeyword = len(words) - counterKeyword = Counter(words) - indexMatch = [] - - for i in range(len(s) - lenKeyword + 1): - counterKeywordCheck = counterKeyword.copy() - startIndex = i - totalMatch = 0 - - while totalMatch < totalKeyword: - isMatch = False - for keyword in counterKeywordCheck: - if counterKeywordCheck[keyword] > 0 and str(s).startswith(keyword, startIndex): - counterKeywordCheck[keyword] -= 1 - startIndex += len(keyword) - totalMatch += 1 - isMatch = True - break - - if not isMatch: - break - - if totalMatch == totalKeyword: - indexMatch.append(i) - - return indexMatch - - -print(Solution().findSubstring("barfoothefoobarman", ["foo","bar"])) #[0,9] -# print(Solution().findSubstring("barfoofoobarthefoobarman", ["bar","foo","the"])) #[0,9] -# print(Solution().findSubstring("foobarfoobar", ["foo","bar"])) #[0,3,6] -print(Solution().findSubstring("foobarfoobar", ["foo","bar"])) #[0,3,6] \ No newline at end of file diff --git a/Medium/add_two_numbers.py b/Medium/add_two_numbers.py deleted file mode 100644 index e8d114d..0000000 --- a/Medium/add_two_numbers.py +++ /dev/null @@ -1,32 +0,0 @@ -# Definition for singly-linked list. -class ListNode(object): - def __init__(self, val=0, next=None): - self.val = val - self.next = next - -class Solution(object): - def addTwoNumbers(self, l1, l2): - node = ListNode() - current = node - carry = 0 - - while l1 or l2 or carry: - val1 = l1.val if l1 else 0 - val2 = l2.val if l2 else 0 - - s = val1 + val2 + carry - carry = s // 10 - current.next = ListNode(s % 10) - current = current.next - - if l1: - l1 = l1.next - - if l2: - l2 = l2.next - - return node.next - -print(Solution().addTwoNumbers([2, 4, 3], [5, 6, 4])) -print(Solution().addTwoNumbers([9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9])) -print(Solution().addTwoNumbers([0], [0])) \ No newline at end of file diff --git a/Medium/divide_to_integers.py b/Medium/divide_to_integers.py deleted file mode 100644 index 06eda87..0000000 --- a/Medium/divide_to_integers.py +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def divide(self, dividend, divisor): - """ - :type dividend: int - :type divisor: int - :rtype: int - """ - INT_MIN = - (2**31) - INT_MAX = (2**31) - 1 - - if dividend < INT_MIN: - dividend = INT_MIN - - if divisor > INT_MAX: - divisor = INT_MAX - - if divisor == 0: - return 0 - - divideNumber = int(float(dividend) / float(divisor)) - - if divideNumber > INT_MAX: - return INT_MAX - elif divideNumber < INT_MIN: - return INT_MIN - - return divideNumber - - - -print(Solution().divide(10, 3)); #3 -print(Solution().divide(7, -3)); #-2 -print(Solution().divide(-2147483648, -1)); #2147483647 -print(Solution().divide(2147483647, 2)); #1073741823 \ No newline at end of file diff --git a/Medium/find_first_and_last_position_of_element_in_sorted_array.py b/Medium/find_first_and_last_position_of_element_in_sorted_array.py deleted file mode 100644 index dfd4cd7..0000000 --- a/Medium/find_first_and_last_position_of_element_in_sorted_array.py +++ /dev/null @@ -1,23 +0,0 @@ -class Solution(object): - def searchRange(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - collectRange = [] - for i, n in enumerate(nums): - if n == target: - collectRange.append(i) - - if len(collectRange) == 0: - return [-1, -1] - elif len(collectRange) == 1: - return 2*collectRange - else: - return [collectRange[0], collectRange[-1]] - -print(Solution().searchRange([5,7,7,8,8,10], 8)) -print(Solution().searchRange([1], 1)) -print(Solution().searchRange([3,3,3], 3)) -print(Solution().searchRange([0,0,1,2,2], 2)) \ No newline at end of file diff --git a/Medium/integer_to_roman.py b/Medium/integer_to_roman.py deleted file mode 100644 index 9f179a6..0000000 --- a/Medium/integer_to_roman.py +++ /dev/null @@ -1,28 +0,0 @@ -import math - -class Solution(object): - def intToRoman(self, num): - """ - :type num: int - :rtype: str - """ - symbolMap = [ - ("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), - ("C", 100), ("XC", 90), ("L", 50), ("XL", 40), - ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1) - ] - - romanText = "" - - for symbol, val in symbolMap: - if num >= val: - totalSymbol = int(math.floor(num/val)) - for i in range(totalSymbol): - romanText += symbol - num -= val - - return romanText - - -print(Solution().intToRoman(3749)); #MMMDCCXLIX -print(Solution().intToRoman(58)); #LVIII \ No newline at end of file diff --git a/Medium/longest_palindrome_substring.py b/Medium/longest_palindrome_substring.py deleted file mode 100644 index c4d3f03..0000000 --- a/Medium/longest_palindrome_substring.py +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def longestPalindrome(self, s): - """ - :type s: str - :rtype: str - """ - if not s or len(s) > 1000: - return s - - if s == str(s)[::-1]: - return s - - resultMatch = s[0] - for i in range(len(s)): - for j in range(i + 1, len(s) + 1): - if str(s)[i] != str(s)[j-1]: - continue - - if j>1 and i+1 < len(s) and str(s)[i+1] != str(s)[j-2]: - continue - - if len(resultMatch) >= j - i: - continue - - strJoin = str(s)[i:j] - - if strJoin == str(strJoin)[::-1]: - resultMatch = strJoin - - return resultMatch - -print(Solution().longestPalindrome("cbbd")) -print(Solution().longestPalindrome("babad")) -print(Solution().longestPalindrome("abcdbbfcba")) \ No newline at end of file diff --git a/Medium/longest_subtstring_without_repeating_characters.py b/Medium/longest_subtstring_without_repeating_characters.py deleted file mode 100644 index c0cebd5..0000000 --- a/Medium/longest_subtstring_without_repeating_characters.py +++ /dev/null @@ -1,30 +0,0 @@ -class Solution(object): - def lengthOfLongestSubstring(self, s): - """ - :type s: str - :rtype: int - """ - if not s or len(s) > 50000: - return 0 - - longestSubtstring = 1 - startIndex = {} - startPosition = 0 - - for i, c in enumerate(s): - if c in startIndex and startIndex[c] >= startPosition: - startPosition = startIndex[c] + 1 - - startIndex[c] = i - longestSubtstring = max(longestSubtstring, i - startPosition + 1) - - return longestSubtstring - -print(Solution().lengthOfLongestSubstring("abcabcbb")) #3 -print(Solution().lengthOfLongestSubstring("bbbbb")) #1 -print(Solution().lengthOfLongestSubstring("pwwkew")) #3 -print(Solution().lengthOfLongestSubstring("")) #0 -print(Solution().lengthOfLongestSubstring("au")) #2 -print(Solution().lengthOfLongestSubstring("aab")) #2 - -#NOTE: TIME OUT ERROR on Leetcode diff --git a/Medium/reverse_integer.py b/Medium/reverse_integer.py deleted file mode 100644 index 5b9867b..0000000 --- a/Medium/reverse_integer.py +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def reverse(self, x): - """ - :type x: int - :rtype: int - """ - strX = str(x) - isNegative = strX[0] == "-" - - if isNegative: - strX = "-"+strX[:0:-1] - else: - strX = strX[::-1] - - convToInteger = int(strX) - - if convToInteger < -(2**31) or convToInteger > (2**31)-1: - return 0 - - return convToInteger - -print(Solution().reverse(123)); #321 -print(Solution().reverse(-123)); #-321 -print(Solution().reverse(1534236469)); #0 \ No newline at end of file diff --git a/Medium/string_to_integer_atoi.py b/Medium/string_to_integer_atoi.py deleted file mode 100644 index 3c993e9..0000000 --- a/Medium/string_to_integer_atoi.py +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def myAtoi(self, s): - """ - :type s: str - :rtype: int - """ - s = s.strip() - cStr = [] - t = 1 - for i, c in enumerate(s): - if i == 0 and c == "-": - t = -1 - continue - - try: - if c not in ["0", "."] and not int(c): - break - - cStr.append(c) - except: - break - - if len(cStr) == 0: - return 0 - - nums = float("".join(cStr)) * t - - if nums <= -2**31-1: - return -2**31-1 - - if nums >= 2**31-1: - return 2**31-1 - - return int(nums) \ No newline at end of file diff --git a/Medium/three_sum.py b/Medium/three_sum.py deleted file mode 100644 index aeb3319..0000000 --- a/Medium/three_sum.py +++ /dev/null @@ -1,53 +0,0 @@ -class Solution(object): - def threeSum(self, nums): - """ - :type nums: List[int] - :rtype: List[List[int]] - """ - collectSum = [] - - if len(nums) < 3 or len(nums) > 3000: - return collectSum - - totalNum = len(nums) - nums = sorted(nums) - - for i in range(totalNum - 2): - if i > 0 and nums[i] == nums[i-1]: - continue - - iLeft, iRight = i+1, totalNum-1 - while iLeft < iRight : - listSumNum = sorted([nums[iLeft], nums[i], nums[iRight]]) - sumNum = sum(listSumNum) - if sumNum == 0: - collectSum.append(listSumNum) - while iLeft < iRight and nums[iLeft] == nums[iLeft+1]: - iLeft += 1 - - while iLeft < iRight and nums[iRight] == nums[iRight-1]: - iRight -= 1 - - iLeft += 1 - iRight -= 1 - elif sumNum < 0: - iLeft += 1 - else: - iRight -= 1 - - def sortListNum(num): - return num[2] - - collectSum.sort(key=sortListNum) - - return collectSum - - -print(Solution().threeSum([-1, 0, 1, 2, -1, -4])) #[[-1,-1,2],[-1,0,1]] -print(Solution().threeSum([0, 0, 0])) #[[0,0,0]] -print(Solution().threeSum([3, -2, 1, 0])) #[] -print(Solution().threeSum([1, -1, -1, 0])) #[[-1,0,1]] -print(Solution().threeSum([-1, 0, 1, 0])) #[[-1,0,1]] -print(Solution().threeSum([2, -3, 0, -2, -5, -5, -4, 1, 2, -2, 2, 0, 2, -4, 5, 5, -10])) -#[[-10,5,5],[-5,0,5],[-4,2,2],[-3,-2,5],[-3,1,2],[-2,0,2]] - \ No newline at end of file diff --git a/Medium/three_sum_closest.py b/Medium/three_sum_closest.py deleted file mode 100644 index 20cfb04..0000000 --- a/Medium/three_sum_closest.py +++ /dev/null @@ -1,40 +0,0 @@ -class Solution(object): - def threeSumClosest(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: int - """ - if len(nums) < 3 or len(nums) > 3000 : return 0 - - totalNum = len(nums) - nums = sorted(nums) - lastSumClosest = nums[0] + nums[1] + nums[2] - - for i in range(totalNum - 1): - iLeft, iRight = i+1, totalNum-1 - while iLeft < iRight: - sumNum = nums[iLeft] + nums[i] + nums[iRight] - closest = abs(target - sumNum) - lastClosest = abs(target - lastSumClosest) - - if target == sumNum: - return sumNum - - if closest < lastClosest: - lastSumClosest = sumNum - - if sumNum < target: - iLeft += 1 - else: - iRight -= 1 - - return lastSumClosest - -print(Solution().threeSumClosest([-1, 2, 1, -4], 1)) #2 -print(Solution().threeSumClosest([0, 0, 0], 1)) #0 -print(Solution().threeSumClosest([0, 1, 2], 3)) #3 -print(Solution().threeSumClosest([10, 20, 30, 40, 50, 60, 70, 80, 90], 1)) #60 -print(Solution().threeSumClosest([4, 0, 5, -5, 3, 3, 0, -4, -5], -2)) #-2 -print(Solution().threeSumClosest([-4, 2, 2, 3, 3, 3], 0)) #0 -print(Solution().threeSumClosest([1, 1, 1, 0], 100)) #3 \ No newline at end of file diff --git a/Medium/zigzag_conversion.py b/Medium/zigzag_conversion.py deleted file mode 100644 index d487a7a..0000000 --- a/Medium/zigzag_conversion.py +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def convert(self, s, numRows): - """ - :type s: str - :type numRows: int - :rtype: str - """ - if len(s) == 0 or len(s) > 1000 or numRows <= 1 or numRows > 1000: - return s - - collectZigzag = ["" for _ in range(numRows)] - currRow = 0 - isStraight = True - - for _, c in enumerate(s): - if currRow == 0: - isStraight = True - elif currRow == numRows - 1: - isStraight = False - - collectZigzag[currRow] += c - - if isStraight: - currRow += 1 - else: - currRow -= 1 - - - return "".join(collectZigzag) - - -# print(Solution().convert("PAYPALISHIRING", 3)) -print(Solution().convert("AB", 1)) - \ No newline at end of file