From 9e8770edda3a4a61310e0df01b13d077165e3d07 Mon Sep 17 00:00:00 2001 From: S-Sanyal Date: Mon, 5 Oct 2020 01:20:09 +0530 Subject: [PATCH 001/161] Added Minimum_Number_of_K_Consecutive_Bit_Flips --- ...inimum_Number_of_K_Consecutive_Bit_Flips.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LeetCode/0995_Minimum_Number_of_K_Consecutive_Bit_Flips.py diff --git a/LeetCode/0995_Minimum_Number_of_K_Consecutive_Bit_Flips.py b/LeetCode/0995_Minimum_Number_of_K_Consecutive_Bit_Flips.py new file mode 100644 index 0000000..0ec30ef --- /dev/null +++ b/LeetCode/0995_Minimum_Number_of_K_Consecutive_Bit_Flips.py @@ -0,0 +1,18 @@ +class Solution: + def minKBitFlips(self, A: List[int], K: int) -> int: + n = len(A) + flips = [0]*(n+1); ans = 0 + for i in range(n): + flips[i] += flips[i-1] if i > 0 else 0 + + if not A[i] ^ (flips[i]%2): + if i + K - 1 >= n : + print(i, K) + return -1 + ans += 1 + flips[i] += 1 + flips[i+K] -= 1 + + return ans + + \ No newline at end of file From 61718fbe77d4c7c91c0d3237d12fc4dc956869ec Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Wed, 7 Oct 2020 22:43:57 +0530 Subject: [PATCH 002/161] Added Anikdas file --- codechecker.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 codechecker.py diff --git a/codechecker.py b/codechecker.py new file mode 100644 index 0000000..c286bf9 --- /dev/null +++ b/codechecker.py @@ -0,0 +1,71 @@ +import requests, os, re, json +from github import Github + +from dotenv import load_dotenv + +load_dotenv(dotenv_path='sample.env') + +# load details from ENV +repo_name = os.getenv("REPO_NAME") +access_token = os.getenv("GITHUB_ACCESS_TOKEN") +pull_number = int(os.getenv("PR_NUMBER")) +leetcode_csrf_token = os.getenv("LEETCODE_CSRF_TOKEN") +leetcode_session_token = os.getenv("LEETCODE_SESSION_TOKEN") + +# authentication +g = Github(access_token) +repo = g.get_repo(repo_name) + +# get PR details +pull = repo.get_pull(pull_number) +all_files = pull.get_files() + +# get details of files from PR +file_url = "" +problem_name = "" +for i in all_files: + if i.filename[-3:] == ".py": + file_url = i.raw_url + problem_name = i.filename.lower() + +# parse question id and problem name +question_id = int(problem_name[0:4]) +problem_name = re.sub("_", "-", problem_name[5:-3]) + +# get file code +r = requests.get(file_url) +code = r.text + +# craft request +leetcode_submission_url = f"https://leetcode.com/problems/{problem_name}/submit/" +language = "python3" +headers = { + "Origin": "https://leetcode.com", + "content-type": "application/json", + "X-CSRFToken": leetcode_csrf_token, + "Referer": leetcode_submission_url, + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0", + # "Cookie": f"csrftoken={leetcode_csrf_token};LEETCODE_SESSION={leetcode_session_token}", +} +cookies = { + "csrftoken": leetcode_csrf_token, + "LEETCODE_SESSION": leetcode_session_token, +} +body = {"question_id": str(question_id), "lang": language, "typed_code": code} + +# send request +submit = requests.post( + leetcode_submission_url, headers=headers, data=body, cookies=cookies +) + +print(submit.status_code) + +# get from submit url response +submission_id = "" + +# check submission against submission_id +leetcode_checker_url = f"https://leetcode.com/submissions/detail/{submission_id}/check/" + + +# sample request body extracted from network tab: {"question_id":"231","lang":"python3","typed_code":"class Solution:\n def isPowerOfTwo(self, x: int) -> bool:\n return (x != 0) and ((x & (x - 1)) == 0); \n"} +# get status of submission \ No newline at end of file From d57bc851a2c81180fc70fa8d19c514d27f669c2e Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Wed, 7 Oct 2020 22:49:20 +0530 Subject: [PATCH 003/161] Added file to check --- LeetCode/0001_Two_Sum.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 LeetCode/0001_Two_Sum.py diff --git a/LeetCode/0001_Two_Sum.py b/LeetCode/0001_Two_Sum.py new file mode 100644 index 0000000..38a449c --- /dev/null +++ b/LeetCode/0001_Two_Sum.py @@ -0,0 +1,10 @@ +class Solution(object): + def twoSum(self, nums, target): + if len(nums) <= 1: + return False + buff_dict = {} + for i in range(len(nums)): + if nums[i] in buff_dict: + return [buff_dict[nums[i]], i] + else: + buff_dict[target - nums[i]] = i \ No newline at end of file From 7e103464c74f66e20128f0e9790d59591630b19c Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:58:36 -0400 Subject: [PATCH 004/161] Upload 0028_strStr.py to Leetcode folder https://leetcode.com/problems/implement-strstr/ --- LeetCode/0028_strStr.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 LeetCode/0028_strStr.py diff --git a/LeetCode/0028_strStr.py b/LeetCode/0028_strStr.py new file mode 100644 index 0000000..b4ab756 --- /dev/null +++ b/LeetCode/0028_strStr.py @@ -0,0 +1,7 @@ +class Solution: + def strStr(self, haystack: str, needle: str) -> int: + try: + res = haystack.index(needle) + return res + except: + return -1 if needle else 0 From 390389299d74f9e25d808e771ec95b4953f5eb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Kiglics?= Date: Thu, 8 Oct 2020 20:14:49 +0200 Subject: [PATCH 005/161] solution for problem 165 --- LeetCode/0165_Compare_Version_Numbers.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/0165_Compare_Version_Numbers.py diff --git a/LeetCode/0165_Compare_Version_Numbers.py b/LeetCode/0165_Compare_Version_Numbers.py new file mode 100644 index 0000000..33fc300 --- /dev/null +++ b/LeetCode/0165_Compare_Version_Numbers.py @@ -0,0 +1,14 @@ +class Solution: + def compareVersion(self, version1: str, version2: str) -> int: + v1 = version1.split(".") + v2 = version2.split(".") + while len(v1) < len(v2): + v1.append("0") + while len(v2) < len(v1): + v2.append("0") + for i in range(len(v1)): + a = int(v1[i]) + b = int(v2[i]) + if a != b: + return (a-b)//abs(a-b) + return 0 From c2308836f799169af14ceb351579def6bb43e03f Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Thu, 8 Oct 2020 15:16:51 -0400 Subject: [PATCH 006/161] Added 0046_Permutations https://leetcode.com/problems/permutations/ --- LeetCode/0046_Permutations.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/LeetCode/0046_Permutations.py b/LeetCode/0046_Permutations.py index 4456739..39205ed 100644 --- a/LeetCode/0046_Permutations.py +++ b/LeetCode/0046_Permutations.py @@ -1,12 +1,3 @@ -class Solution: - def permutations(self, nums: List[int]): - if not nums: - yield [] - for num in nums: - remaining = list(nums) - remaining.remove(num) - for perm in self.permutations(remaining): - yield [num] + list(perm) - - def permute(self, nums: List[int]) -> List[List[int]]: - return list(self.permutations(nums)) +class Solution: + def permute(self, nums: List[int]) -> List[List[int]]: + return [list(x) for x in permutations(nums)] From cf23ab8b46f9840997d43037cff3dbf8eada0599 Mon Sep 17 00:00:00 2001 From: Alexey Ilyukhov Date: Sat, 10 Oct 2020 04:26:06 +0300 Subject: [PATCH 007/161] Add 1340. Jump Game V --- LeetCode/1340_Jump_Game_V.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 LeetCode/1340_Jump_Game_V.py diff --git a/LeetCode/1340_Jump_Game_V.py b/LeetCode/1340_Jump_Game_V.py new file mode 100644 index 0000000..1094f4d --- /dev/null +++ b/LeetCode/1340_Jump_Game_V.py @@ -0,0 +1,28 @@ +class Solution(object): + def maxJumps(self, arr, d): + """ + :type arr: List[int] + :type d: int + :rtype: int + """ + + dp = [1] * len(arr) + + for i, _ in sorted(enumerate(arr), key=lambda x: x[1]): + max_h = None + for j in range(i - 1, max(i - d - 1, -1), -1): + max_h = max(max_h, arr[j]) + if max_h < arr[i]: + dp[i] = max(dp[i], dp[j] + 1) + else: + break + + max_h = None + for j in range(i + 1, min(i + d + 1, len(arr))): + max_h = max(max_h, arr[j]) + if max_h < arr[i]: + dp[i] = max(dp[i], dp[j] + 1) + else: + break + + return max(dp) From 574174912d9fa9e9337106f26e46c7e6086e6d1b Mon Sep 17 00:00:00 2001 From: Bhawesh Bhansali Date: Sat, 10 Oct 2020 10:19:07 +0530 Subject: [PATCH 008/161] Create 1589-maximum-sum-obtained-of-any-permutation.py --- ...maximum-sum-obtained-of-any-permutation.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 LeetCode/1589-maximum-sum-obtained-of-any-permutation.py diff --git a/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py b/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py new file mode 100644 index 0000000..9735428 --- /dev/null +++ b/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py @@ -0,0 +1,46 @@ +import itertools + + +class Solution(object): + def maxSumRangeQuery(self, nums, requests): + """ + :type nums: List[int] + :type requests: List[List[int]] + :rtype: int + """ + def addmod(a, b, mod): # avoid overflow in other languages + a %= mod + b %= mod + if mod-a <= b: + b -= mod + return a+b + + def mulmod(a, b, mod): # avoid overflow in other languages + a %= mod + b %= mod + if a < b: + a, b = b, a + result = 0 + while b > 0: + if b%2 == 1: + result = addmod(result, a, mod) + a = addmod(a, a, mod) + b //= 2 + return result + + MOD = 10**9+7 + + count = [0]*len(nums) + for start, end in requests: + count[start] += 1 + if end+1 < len(count): + count[end+1] -= 1 + for i in xrange(1, len(count)): + count[i] += count[i-1] + nums.sort() + count.sort() + result = 0 + for i, (num, c) in enumerate(itertools.izip(nums, count)): + # result = addmod(result, mulmod(num, c, MOD), MOD) + result = (result+num*c)%MOD + return result From 72d674e0cfb5709201bc7ae45cb0ae23f6057b61 Mon Sep 17 00:00:00 2001 From: Sagnik Mazumder Date: Sat, 10 Oct 2020 11:36:10 +0530 Subject: [PATCH 009/161] added solution to leetcode problem 1346 --- LeetCode/1346_Check_if_N_and_its_Double_Exist.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/1346_Check_if_N_and_its_Double_Exist.py diff --git a/LeetCode/1346_Check_if_N_and_its_Double_Exist.py b/LeetCode/1346_Check_if_N_and_its_Double_Exist.py new file mode 100644 index 0000000..8c01a86 --- /dev/null +++ b/LeetCode/1346_Check_if_N_and_its_Double_Exist.py @@ -0,0 +1,14 @@ +class Solution: + def tribonacci(self, n: int) -> int: + a, b, c = 0, 1, 1 + if n == 0: + return 0 + elif n == 1 or n == 2: + return 1 + else: + for _ in range(n - 2): + temp = a + b + c + a = b + b = c + c = temp + return temp From 67881f02c54d1351ff9da66c82df32762186fde3 Mon Sep 17 00:00:00 2001 From: aman1833 <33142696+aman1833@users.noreply.github.com> Date: Sat, 10 Oct 2020 19:38:54 +0530 Subject: [PATCH 010/161] Create fast_fibonacci.py --- fast_fibonacci.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 fast_fibonacci.py diff --git a/fast_fibonacci.py b/fast_fibonacci.py new file mode 100644 index 0000000..e7bdfac --- /dev/null +++ b/fast_fibonacci.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +import sys + + +def fibonacci(n: int) -> int: + """ + return F(n) + >>> [fibonacci(i) for i in range(13)] + [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144] + """ + if n < 0: + raise ValueError("Negative arguments are not supported") + return _fib(n)[0] + + +# returns (F(n), F(n-1)) +def _fib(n: int) -> tuple[int, int]: + if n == 0: # (F(0), F(1)) + return (0, 1) + + # F(2n) = F(n)[2F(n+1) − F(n)] + # F(2n+1) = F(n+1)^2+F(n)^2 + a, b = _fib(n // 2) + c = a * (b * 2 - a) + d = a * a + b * b + return (d, c + d) if n % 2 else (c, d) + + +if __name__ == "__main__": + n = int(sys.argv[1]) + print(f"fibonacci({n}) is {fibonacci(n)}") From de9c63c0d93c4b5b34cde57e6dd9e246062d7053 Mon Sep 17 00:00:00 2001 From: sree_gaya3 Date: Sat, 10 Oct 2020 20:46:35 +0530 Subject: [PATCH 011/161] Added the Solution Code for problem 1599 issue --- ..._Profit_of_Operating_a_Centennial_Wheel.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py diff --git a/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py b/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py new file mode 100644 index 0000000..64ed034 --- /dev/null +++ b/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py @@ -0,0 +1,38 @@ +class Solution(object): + def minOperationsMaxProfit(self, customers, boardingCost, runningCost) : + """ + :type customers: List[int] + :type boardingCose: int + :type runningCose: int + :rtype: int + """ + wait = 0 + pro = 0 high = 0 + res = -1 + for i in range(len(customers)): + vacc = 4 - wait + if vacc <= 0: + wait += customers[i] - 4 + pro += 4 * boardingCost - runningCost + # board all + elif customers[i] <= vacc: # board=customers[i]+wait + pro += boardingCost * (customers[i] + wait) - runningCost + wait = 0 + else: + pro += boardingCost * 4 - runningCost + wait += customers[i] - 4 + if pro > high: + high = pro + res = i + # determine after all arrives + pro_per = boardingCost * 4 - runningCost + if pro_per > 0: + last = wait % 4 + if wait >= 4: + if boardingCost * last - runningCost > 0: + return len(customers) + wait // 4 + 1 + else: + return len(customers) + wait // 4 + if boardingCost * last - runningCost > 0: + return len(customers) + 1 + return res + 1 if res >= 0 else -1 From d57b3c6398113c9b3451222db0cd88067defe67d Mon Sep 17 00:00:00 2001 From: sree_gaya3 Date: Sat, 10 Oct 2020 20:56:19 +0530 Subject: [PATCH 012/161] Added the Solution Code for problem 1599 issue #568 --- .../1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py b/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py index 64ed034..29c19dc 100644 --- a/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py +++ b/LeetCode/1599_Maximum_Profit_of_Operating_a_Centennial_Wheel.py @@ -7,7 +7,8 @@ def minOperationsMaxProfit(self, customers, boardingCost, runningCost) : :rtype: int """ wait = 0 - pro = 0 high = 0 + pro = 0 + high = 0 res = -1 for i in range(len(customers)): vacc = 4 - wait From 7c8885fb2f1c6fa0b85187d8eb03bdf30ca2865f Mon Sep 17 00:00:00 2001 From: Shreeji <55141517+Shreejichandra@users.noreply.github.com> Date: Sat, 10 Oct 2020 21:23:40 +0530 Subject: [PATCH 013/161] Create 0452_Minimum_Number_of_Arrows_to_Burst_Balloons.py --- ...nimum_Number_of_Arrows_to_Burst_Balloons.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LeetCode/0452_Minimum_Number_of_Arrows_to_Burst_Balloons.py diff --git a/LeetCode/0452_Minimum_Number_of_Arrows_to_Burst_Balloons.py b/LeetCode/0452_Minimum_Number_of_Arrows_to_Burst_Balloons.py new file mode 100644 index 0000000..bd55865 --- /dev/null +++ b/LeetCode/0452_Minimum_Number_of_Arrows_to_Burst_Balloons.py @@ -0,0 +1,18 @@ +class Solution: + def findMinArrowShots(self, points: List[List[int]]) -> int: + if points == []: + return 0 + points.sort(key = lambda x: x[0]) + start = points[0][0] + end = points[0][1] + ans = len(points) + for i in range(1, len(points)): + if start <= points[i][0] <= end: + ans -= 1 + if points[i][1] < end: + end = points[i][1] + else: + start = points[i][0] + end = points[i][1] + + return ans From 166b1a308ba8746bbebca549d926b51844d45705 Mon Sep 17 00:00:00 2001 From: Davi Fontenele Date: Sat, 10 Oct 2020 12:57:58 -0300 Subject: [PATCH 014/161] Create 0006_ZigZag_Conversion.py Solution for ZigZag Conversion in python --- LeetCode/0006_ZigZag_Conversion.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LeetCode/0006_ZigZag_Conversion.py diff --git a/LeetCode/0006_ZigZag_Conversion.py b/LeetCode/0006_ZigZag_Conversion.py new file mode 100644 index 0000000..ab9f2c0 --- /dev/null +++ b/LeetCode/0006_ZigZag_Conversion.py @@ -0,0 +1,21 @@ +class Solution: + # @param {string} s + # @param {integer} numRows + # @return {string} + def convert(self, s, numRows): + + if numRows == 1: + return s + + rows = ["" for i in range(numRows)] + + direction = -1 + row = 0 + for i in range(len(s)): + + rows[row]+=s[i] + if (row == 0 or row==numRows-1): + direction *= -1 + row+=direction + + return "".join(rows) From fe872c09ec950e1cd951bc836099a074c6e1c945 Mon Sep 17 00:00:00 2001 From: sree_gaya3 Date: Sat, 10 Oct 2020 21:34:16 +0530 Subject: [PATCH 015/161] Solution to Problem 1608 issue #571 --- ...rray_With_X_Elements_Greater_Than_or_Equal_x.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py diff --git a/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py b/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py new file mode 100644 index 0000000..630f5cd --- /dev/null +++ b/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py @@ -0,0 +1,14 @@ +class Solution(object): + def specialArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + nums.sort() + out = -1 + for i in range(len(nums)): + if nums[~i]>=i+1: + if i==len(nums)-1 or nums[~(i+1)] Date: Sat, 10 Oct 2020 21:41:38 +0530 Subject: [PATCH 016/161] Added Solution to the Problem 1608 issue #571 --- ...rray_With_X_Elements_Greater_Than_or_Equal_x.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py diff --git a/LeetCode/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py b/LeetCode/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py new file mode 100644 index 0000000..630f5cd --- /dev/null +++ b/LeetCode/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py @@ -0,0 +1,14 @@ +class Solution(object): + def specialArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + nums.sort() + out = -1 + for i in range(len(nums)): + if nums[~i]>=i+1: + if i==len(nums)-1 or nums[~(i+1)] Date: Sat, 10 Oct 2020 21:44:03 +0530 Subject: [PATCH 017/161] Removed one wrong file with a typo --- ...rray_With_X_Elements_Greater_Than_or_Equal_x.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py diff --git a/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py b/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py deleted file mode 100644 index 630f5cd..0000000 --- a/1608_Special_Array_With_X_Elements_Greater_Than_or_Equal_x.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def specialArray(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - nums.sort() - out = -1 - for i in range(len(nums)): - if nums[~i]>=i+1: - if i==len(nums)-1 or nums[~(i+1)] Date: Sat, 10 Oct 2020 12:16:47 -0400 Subject: [PATCH 018/161] added solution to 1588 --- 1588_SumOfAllOddLengthSubarrays.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 1588_SumOfAllOddLengthSubarrays.py diff --git a/1588_SumOfAllOddLengthSubarrays.py b/1588_SumOfAllOddLengthSubarrays.py new file mode 100644 index 0000000..f689d7a --- /dev/null +++ b/1588_SumOfAllOddLengthSubarrays.py @@ -0,0 +1,15 @@ +class Solution(object): + def sumOddLengthSubarrays(self, arr): + + _sum = 0 + length = len(arr) + sub_len = 1 + start = 0 + + while sub_len <= length: + for start in range(length - sub_len + 1): + for i in range(start, start + sub_len): + _sum = _sum + arr[i] + sub_len = sub_len + 2 + + return _sum \ No newline at end of file From b2220fe333e571a26f5cd3fa17ebe3577f54320e Mon Sep 17 00:00:00 2001 From: tejasvicsr1 Date: Sat, 10 Oct 2020 21:49:38 +0530 Subject: [PATCH 019/161] Solution to the problem 1365 #603 --- ...Many_Numbers_Are_Smaller_Than_the_Current_Number.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py diff --git a/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py b/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py new file mode 100644 index 0000000..bb892a0 --- /dev/null +++ b/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py @@ -0,0 +1,10 @@ +class Solution: + def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: + ans = [] + for i in range(0, len(nums)): + soln = 0 + for j in range(0, len(nums)): + if(nums[j] < nums[i] and j != i): + soln += 1 + ans. append(soln) + return ans \ No newline at end of file From 922809f67b717f6af59f6376d782d84ac23a5502 Mon Sep 17 00:00:00 2001 From: matheusphalves Date: Sat, 10 Oct 2020 13:20:41 -0300 Subject: [PATCH 020/161] Added 0342_Power_Of_Four.py --- LeetCode/0342_Power_Of_Four.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 LeetCode/0342_Power_Of_Four.py diff --git a/LeetCode/0342_Power_Of_Four.py b/LeetCode/0342_Power_Of_Four.py new file mode 100644 index 0000000..a3711ec --- /dev/null +++ b/LeetCode/0342_Power_Of_Four.py @@ -0,0 +1,9 @@ +import math +class Solution: + #Solution without loops/recursion + def isPowerOfFour(self, num: int) -> bool: + if(num!=0): #number 0 there isn't in the logarithmic function domain! + exponent = math.log(abs(num), 4) #I will discover the number which multiply 4 nth times. The result must be equal to num. Ex: 4^2 = 16 + #However, the exponent must to be an integer value for num to be a power of 4. For example, there are no 4's half number power! + return int(math.pow(4, int(exponent)))==num + return False #number zero was the input \ No newline at end of file From 787c4f299247e15f4f9491fcf37c64615c232540 Mon Sep 17 00:00:00 2001 From: frank731 <38197177+frank731@users.noreply.github.com> Date: Sat, 10 Oct 2020 09:23:34 -0700 Subject: [PATCH 021/161] Create 0437_Path_Sum_III.py --- 0437_Path_Sum_III.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 0437_Path_Sum_III.py diff --git a/0437_Path_Sum_III.py b/0437_Path_Sum_III.py new file mode 100644 index 0000000..f85e902 --- /dev/null +++ b/0437_Path_Sum_III.py @@ -0,0 +1,31 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + count = 0 + past_sums = {} + + def pathSum(self, root: TreeNode, sum: int) -> int: + if root is not None: + self.recurse(root, 0, sum) + return self.count + + def recurse(self, node, summed, target): + if node is None: + return False + else: + summed += node.val + if summed == target: + self.count += 1 + if summed - target in self.past_sums: + self.count += self.past_sums[summed - target] + if summed in self.past_sums: + self.past_sums[summed] += 1 + else: + self.past_sums[summed] = 1 + self.recurse(node.left, summed, target) + self.recurse(node.right, summed, target) + self.past_sums[summed] -= 1 From c9f5b9276de10f49324707116dcce0527536e325 Mon Sep 17 00:00:00 2001 From: frank731 <38197177+frank731@users.noreply.github.com> Date: Sat, 10 Oct 2020 09:25:11 -0700 Subject: [PATCH 022/161] Rename 0437_Path_Sum_III.py to LeetCode/0437_Path_Sum_III.py --- 0437_Path_Sum_III.py => LeetCode/0437_Path_Sum_III.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 0437_Path_Sum_III.py => LeetCode/0437_Path_Sum_III.py (100%) diff --git a/0437_Path_Sum_III.py b/LeetCode/0437_Path_Sum_III.py similarity index 100% rename from 0437_Path_Sum_III.py rename to LeetCode/0437_Path_Sum_III.py From eb446c6e24a2f87ad3ba20f45383267b5ecf4a85 Mon Sep 17 00:00:00 2001 From: Sagnik Mazumder Date: Sat, 10 Oct 2020 21:59:33 +0530 Subject: [PATCH 023/161] updated solution --- .../1346_Check_if_N_and_its_Double_Exist.py | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/LeetCode/1346_Check_if_N_and_its_Double_Exist.py b/LeetCode/1346_Check_if_N_and_its_Double_Exist.py index 8c01a86..1abe45b 100644 --- a/LeetCode/1346_Check_if_N_and_its_Double_Exist.py +++ b/LeetCode/1346_Check_if_N_and_its_Double_Exist.py @@ -1,14 +1,9 @@ class Solution: - def tribonacci(self, n: int) -> int: - a, b, c = 0, 1, 1 - if n == 0: - return 0 - elif n == 1 or n == 2: - return 1 - else: - for _ in range(n - 2): - temp = a + b + c - a = b - b = c - c = temp - return temp + def checkIfExist(self, arr: List[int]) -> bool: + + seen = set() + for x in arr: + if x * 2 in seen or (not x % 2 and x // 2 in seen): + return True + seen.add(x) + return False From 74130ae869066ab3320437bcb15b11fe71ee6984 Mon Sep 17 00:00:00 2001 From: sree_gaya3 Date: Sat, 10 Oct 2020 22:07:09 +0530 Subject: [PATCH 024/161] Added Solution to the problem 1604 issue #574 --- ...hree_or_More_Times_in_a_One_Hour_Period.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 LeetCode/1604_Alert_Using_Same_Key_Card_Three_or_More_Times_in_a_One_Hour_Period.py diff --git a/LeetCode/1604_Alert_Using_Same_Key_Card_Three_or_More_Times_in_a_One_Hour_Period.py b/LeetCode/1604_Alert_Using_Same_Key_Card_Three_or_More_Times_in_a_One_Hour_Period.py new file mode 100644 index 0000000..afd7763 --- /dev/null +++ b/LeetCode/1604_Alert_Using_Same_Key_Card_Three_or_More_Times_in_a_One_Hour_Period.py @@ -0,0 +1,35 @@ +class Solution(object): + def alertNames(self, keyName, keyTime): + """ + :type keyName: List[str] + :type keyTime: List[str] + :rtype: List[str] + """ + mapp = {} + for i in range(len(keyName)): + name = keyName[i] + if(name not in mapp): + mapp[name] = [keyTime[i]] + else: + mapp[name].append(keyTime[i]) + res = [] + for name, arr in mapp.items(): + arr.sort() + for i in range(len(arr)-2): + time= arr[i] + t2 = arr[i+1] + t3 = arr[i+2] + if(time[0:2]=="23"): + endTime = "24:00" + if(t2<=endTime and t3<=endTime and t2>time and t3>time): + res.append(name) + break + else: + start = int(time[0:2]) + endTime = str(start+1)+time[2:] + if(start<9): + endTime = "0"+endTime + if(t2<=endTime and t3<=endTime): + res.append(name) + break + return sorted(res) From ba62c931d74ce10f3732e9dfd1a076147467b9f8 Mon Sep 17 00:00:00 2001 From: zeborg Date: Sat, 10 Oct 2020 22:18:02 +0530 Subject: [PATCH 025/161] Added solution to Problem 867 - Transpose Matrix --- LeetCode/0867_Transpose_Matrix.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 LeetCode/0867_Transpose_Matrix.py diff --git a/LeetCode/0867_Transpose_Matrix.py b/LeetCode/0867_Transpose_Matrix.py new file mode 100644 index 0000000..97fed72 --- /dev/null +++ b/LeetCode/0867_Transpose_Matrix.py @@ -0,0 +1,27 @@ +""" +Problem: Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix. + +Sample input: + [[1,2,3], + [4,5,6], + [7,8,9]] + +Sample output: + [[1,4,7], + [2,5,8], + [3,6,9]] +""" + +class Solution: + def transpose(self, A: List[List[int]]) -> List[List[int]]: + transpose=[] + k=0 + for p in range(len(A[0])): + temp=[] + for i in A: + while k Date: Sat, 10 Oct 2020 22:19:39 +0530 Subject: [PATCH 026/161] Added Solution to Problem 1606 issue #578 --- ...rs_That_Handled_Most_Number_of_Requests.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 LeetCode/1606_Find_Servers_That_Handled_Most_Number_of_Requests.py diff --git a/LeetCode/1606_Find_Servers_That_Handled_Most_Number_of_Requests.py b/LeetCode/1606_Find_Servers_That_Handled_Most_Number_of_Requests.py new file mode 100644 index 0000000..73d5a08 --- /dev/null +++ b/LeetCode/1606_Find_Servers_That_Handled_Most_Number_of_Requests.py @@ -0,0 +1,36 @@ +class Solution(object): + def busiestServers(self, k, arrival, load): + """ + :type k: int + :type arrival: List[int] + :type load: List[int] + :rtype: List[int] + """ + from sortedcontainers import SortedList + avail = SortedList() + for i in range(k): + avail.add(i) + h = [] + count = [0]*k + for i in range(len(arrival)): + s = arrival[i] + e = arrival[i]+load[i] + while h and h[0][0]<=s: + _, j = heappop(h) + avail.add(j) + if len(h)==k: + continue + si = avail.bisect_left(i%k) + if si==len(avail): + ser = avail[0] + else: + ser = avail[si] + avail.remove(ser) + count[ser]+=1 + heappush(h, (e, ser)) + maxReq = max(count) + ans = [] + for i in range(len(count)): + if count[i]==maxReq: + ans.append(i) + return ans From e1c45eb57b7ba4e6119ba8a8067e0333342079cd Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:31:03 -0400 Subject: [PATCH 027/161] Add 0155_Min_stack.py --- LeetCode/0155_Min_stack.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 LeetCode/0155_Min_stack.py diff --git a/LeetCode/0155_Min_stack.py b/LeetCode/0155_Min_stack.py new file mode 100644 index 0000000..cdc92b4 --- /dev/null +++ b/LeetCode/0155_Min_stack.py @@ -0,0 +1,33 @@ +class MinStack: + + def __init__(self): + """ + initialize your data structure here. + """ + self.stack = [] + + + def push(self, x: int) -> None: + self.stack.append(x) + + + def pop(self) -> None: + self.stack.pop() # = self.stack[:-1] #pop() + + + def top(self) -> int: + return self.stack[-1] + + + + def getMin(self) -> int: + return min(self.stack) + + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(x) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() From 07624642411a3f4f87c972e1b3c7dd4571c48385 Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:39:23 -0400 Subject: [PATCH 028/161] Delete 0028_strStr.py --- LeetCode/0028_strStr.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 LeetCode/0028_strStr.py diff --git a/LeetCode/0028_strStr.py b/LeetCode/0028_strStr.py deleted file mode 100644 index b4ab756..0000000 --- a/LeetCode/0028_strStr.py +++ /dev/null @@ -1,7 +0,0 @@ -class Solution: - def strStr(self, haystack: str, needle: str) -> int: - try: - res = haystack.index(needle) - return res - except: - return -1 if needle else 0 From d3f41a58430cd4fc65d71cb30e6fc8297e5670fd Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:42:03 -0400 Subject: [PATCH 029/161] Delete 0046_Permutations.py --- LeetCode/0046_Permutations.py | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 LeetCode/0046_Permutations.py diff --git a/LeetCode/0046_Permutations.py b/LeetCode/0046_Permutations.py deleted file mode 100644 index 39205ed..0000000 --- a/LeetCode/0046_Permutations.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def permute(self, nums: List[int]) -> List[List[int]]: - return [list(x) for x in permutations(nums)] From 352cc3b6cad8a9cb5a4346bac3457aa12f7e4222 Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:44:47 -0400 Subject: [PATCH 030/161] Add files via upload --- LeetCode/0046_Permutations.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LeetCode/0046_Permutations.py diff --git a/LeetCode/0046_Permutations.py b/LeetCode/0046_Permutations.py new file mode 100644 index 0000000..d0ba022 --- /dev/null +++ b/LeetCode/0046_Permutations.py @@ -0,0 +1,12 @@ +class Solution: + def permutations(self, nums: List[int]): + if not nums: + yield [] + for num in nums: + remaining = list(nums) + remaining.remove(num) + for perm in self.permutations(remaining): + yield [num] + list(perm) + + def permute(self, nums: List[int]) -> List[List[int]]: + return list(self.permutations(nums)) From 228afcdd56f15d39c2592295764fba8b247edd02 Mon Sep 17 00:00:00 2001 From: Richard Wi <18545483+riwim@users.noreply.github.com> Date: Sat, 10 Oct 2020 19:45:12 +0200 Subject: [PATCH 031/161] Solve Leet Code 1252 Cells with Odd Values in a Matrix --- LeetCode/1252_Cells_with_Odd_Values_in_a_Matrix.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/1252_Cells_with_Odd_Values_in_a_Matrix.py diff --git a/LeetCode/1252_Cells_with_Odd_Values_in_a_Matrix.py b/LeetCode/1252_Cells_with_Odd_Values_in_a_Matrix.py new file mode 100644 index 0000000..c6dba68 --- /dev/null +++ b/LeetCode/1252_Cells_with_Odd_Values_in_a_Matrix.py @@ -0,0 +1,13 @@ +import numpy as np + +class Solution: + + def get_summation_matrix(self, n: int, m: int, ri: int, ci: int): + mat = np.zeros([n, m], dtype=int) + mat[ri,:] += 1 + mat[:,ci] += 1 + return mat + + def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int: + matrix_inc = sum(self.get_summation_matrix(n, m, ri, ci) for ri, ci in indices) + return np.count_nonzero(matrix_inc % 2 == 1) From c2ac17dded39e0075370e36b7ae3f9cc06bfab0a Mon Sep 17 00:00:00 2001 From: kunatastic Date: Sat, 10 Oct 2020 23:36:49 +0530 Subject: [PATCH 032/161] 0326 Power of three added --- LeetCode/0326_Power_Of_Three.py | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 LeetCode/0326_Power_Of_Three.py diff --git a/LeetCode/0326_Power_Of_Three.py b/LeetCode/0326_Power_Of_Three.py new file mode 100644 index 0000000..d39687d --- /dev/null +++ b/LeetCode/0326_Power_Of_Three.py @@ -0,0 +1,42 @@ +""" +Given an integer, write a function to determine if it is a power of three. + +Example 1: + +Input: 27 +Output: true +Example 2: + +Input: 0 +Output: false +Example 3: + +Input: 9 +Output: true +Example 4: + +Input: 45 +Output: false +Follow up: +Could you do it without using any loop / recursion? +""" +class Solution(object): + def isPowerOfThree(self, n): + if n<1: + return False + elif n == 1: + return True + elif n == 2: + return False + else: + while n > 2: + a, b = divmod(n, 3) + if b == 0: + n = a + else: + break + if n==1: + return True + else: + return False + From b7b61fe978a11b2fac3c075514ed9a84704b1cac Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Sat, 10 Oct 2020 14:25:08 -0400 Subject: [PATCH 033/161] Delete 0046_Permutations.py --- LeetCode/0046_Permutations.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 LeetCode/0046_Permutations.py diff --git a/LeetCode/0046_Permutations.py b/LeetCode/0046_Permutations.py deleted file mode 100644 index d0ba022..0000000 --- a/LeetCode/0046_Permutations.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def permutations(self, nums: List[int]): - if not nums: - yield [] - for num in nums: - remaining = list(nums) - remaining.remove(num) - for perm in self.permutations(remaining): - yield [num] + list(perm) - - def permute(self, nums: List[int]) -> List[List[int]]: - return list(self.permutations(nums)) From d3c7a7b10e9aa33006c8bd3f79434e266687a59c Mon Sep 17 00:00:00 2001 From: Andrew <54547089+ac-tam@users.noreply.github.com> Date: Sat, 10 Oct 2020 14:26:02 -0400 Subject: [PATCH 034/161] Create 0551_ Student_Attendance_Record_I.py --- LeetCode/0551_ Student_Attendance_Record_I.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LeetCode/0551_ Student_Attendance_Record_I.py diff --git a/LeetCode/0551_ Student_Attendance_Record_I.py b/LeetCode/0551_ Student_Attendance_Record_I.py new file mode 100644 index 0000000..f11f0eb --- /dev/null +++ b/LeetCode/0551_ Student_Attendance_Record_I.py @@ -0,0 +1,20 @@ +class Solution: + def checkRecord(self, s: str) -> bool: + aCount = 0; + lCount = 0; + for ch in s: + if ch == "L": + lCount += 1 + else: + lCount = 0 + + if ch == "A": + aCount += 1 + + if lCount > 2: + return False + if aCount > 1: + return False + + return True + From d24c979c57c8ea6b48b16c43ec345373181e089d Mon Sep 17 00:00:00 2001 From: kevin454475 <71903670+kevin454475@users.noreply.github.com> Date: Sat, 10 Oct 2020 14:28:46 -0400 Subject: [PATCH 035/161] Add files via upload was having difficulty figuring out how to rebase my fork as i had tried uploading 46 a couple days ago --- LeetCode/0046_Permutations.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LeetCode/0046_Permutations.py diff --git a/LeetCode/0046_Permutations.py b/LeetCode/0046_Permutations.py new file mode 100644 index 0000000..d0ba022 --- /dev/null +++ b/LeetCode/0046_Permutations.py @@ -0,0 +1,12 @@ +class Solution: + def permutations(self, nums: List[int]): + if not nums: + yield [] + for num in nums: + remaining = list(nums) + remaining.remove(num) + for perm in self.permutations(remaining): + yield [num] + list(perm) + + def permute(self, nums: List[int]) -> List[List[int]]: + return list(self.permutations(nums)) From 481da4bc35b7dd7aac57ae2ecf1cb2e1d025af3e Mon Sep 17 00:00:00 2001 From: Jeff Mikels Date: Sat, 10 Oct 2020 14:50:25 -0400 Subject: [PATCH 036/161] added 0006_ZigZag_Conversion --- LeetCode/0006_ZigZag_Conversion.py | 176 +++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 LeetCode/0006_ZigZag_Conversion.py diff --git a/LeetCode/0006_ZigZag_Conversion.py b/LeetCode/0006_ZigZag_Conversion.py new file mode 100644 index 0000000..2d7de9c --- /dev/null +++ b/LeetCode/0006_ZigZag_Conversion.py @@ -0,0 +1,176 @@ +''' +## Description of the Problem + +The string "PAYPALISHIRING" is written in a zigzag pattern +on a given number of rows like this: + +(you may want to display this pattern in a fixed font for better legibility) + +``` +P A H N +A P L S I I G +Y I R +``` + +And then read line by line: "PAHNAPLSIIGYIR" + +Write the code that will take a string and make this conversion given a number of rows: + +``` +string convert(string s, int numRows); +``` + +## Example 1: +``` +Input: s = "PAYPALISHIRING", numRows = 3 +Output: "PAHNAPLSIIGYIR" +``` + +## Example 2: +``` +Input: s = "PAYPALISHIRING", numRows = 4 +Output: "PINALSIGYAHRPI" +``` + +## Explanation: + +``` +P I N +A L S I G +Y A H R +P I +``` + +## Example 3: + +``` +Input: s = "A", numRows = 1 +Output: "A" +``` + +## Constraints: + +- 1 <= s.length <= 1000 +- s consists of English letters (lower-case and upper-case), ',' and '.'. +- 1 <= numRows <= 1000 + + +## Link To The LeetCode Problem +[6. ZigZag Conversion](https://leetcode.com/problems/zigzag-conversion/) +''' + + +class Solution: + s = '' + numRows = 1 + + # transitionColumns is the number of extra columns needed to get the + # text from the bottom row back to the top row + def zigZagTransitionColumns(self) -> int: + transitionColumns = self.numRows - 2 + if transitionColumns < 0: + transitionColumns = 0 + return transitionColumns + + # patternColumns is the number of columns taken up by each full pattern + # the first column is downward, and then we need columns for the upward + def zigZagPatternColumns(self) -> int: + return 1 + self.zigZagTransitionColumns() + + # patternSize is the number of elements in each repeated pattern + def zigZagPatternLength(self) -> int: + # there are numRows letters in the first column + # followed by one letter per transitionColumn + return self.numRows + self.zigZagTransitionColumns() + + # computes the number of total columns needed by this string + def zigZagMatrixColumns(self) -> int: + patternLength = self.zigZagPatternLength() + fullPatternCount = len(self.s) // patternLength + columns = self.zigZagPatternColumns() * fullPatternCount + + # how many extra letters are there? + extraLetters = len(self.s) - (patternLength * fullPatternCount) + if extraLetters > 0: + columns += 1 + if extraLetters > self.numRows: + columns += extraLetters - self.numRows + return columns + + # converts the index of the input string to the address + # in the output matrix + def zigZagMatrixIndex(self, elementIndex: int) -> tuple: + patternLength = self.zigZagPatternLength() + + # which pattern repetition holds this element (zero-based) + patternOfElement = elementIndex // patternLength + + # where in the pattern repetition is this element + indexInPattern = elementIndex % patternLength + + matrixRow = indexInPattern + matrixColumn = patternOfElement * self.zigZagPatternColumns() + bottomRowIndex = self.numRows - 1 + + # correct the row and column numbers (remember these are zero-based) + if indexInPattern > bottomRowIndex: + extraColumns = indexInPattern - bottomRowIndex + matrixColumn = matrixColumn + extraColumns + + # row decrements by 1 for each extra column + matrixRow = bottomRowIndex - extraColumns + + # i, j + return (matrixColumn, matrixRow) + + # creates a zigzag matrix + def generateZigZagMatrix(self) -> list: + matrix = [] + for i in range(self.zigZagMatrixColumns()): + matrix.append([]) + for j in range(self.numRows): + matrix[i].append('') + for elementIndex, char in enumerate(self.s): + i, j = self.zigZagMatrixIndex(elementIndex) + matrix[i][j] = char + return matrix + + # prints out the zigzag matrix + def generateZigZagString(self, nullChar: str = ' ', lineEndings: str = '\n'): + lines = [] + matrix = self.generateZigZagMatrix() + for j in range(self.numRows): + rowChars = [] + for i in range(self.zigZagMatrixColumns()): + char = matrix[i][j] + rowChars.append(char if char != '' else nullChar) + lines.append(''.join(rowChars)) + return lineEndings.join(lines) + + def zigZagConversion(self, s: str, numRows: int, asMatrix: bool = False) -> str: + ''' + The ZigZag format fills all available rows vertically in the first column, + then, fills rows "diagonally" on the way back up to the top row of a subsequent + column, and then repeats. + + The input string is the normal content. + ''' + self.s = s + self.numRows = numRows + if asMatrix: + return self.generateZigZagString(nullChar=' ', lineEndings='\n') + else: + return self.generateZigZagString(nullChar='', lineEndings='') + + +# testing +if __name__ == '__main__': + toConvert = 'PAYPALISHIRING' + converter = Solution() + for i in range(4): + print(f'\nENCODING: {toConvert} with {i+1} rows') + print('\n-- matrix -----------------') + print(converter.zigZagConversion(toConvert, numRows=i+1, asMatrix=True)) + print('\n-- line -------------------') + print(converter.zigZagConversion(toConvert, numRows=i+1, asMatrix=False)) + print() From a13f0859a57a766ccb018cc5278a8183fc54427e Mon Sep 17 00:00:00 2001 From: frank731 <38197177+frank731@users.noreply.github.com> Date: Sat, 10 Oct 2020 12:17:10 -0700 Subject: [PATCH 037/161] Create 0445_Add_Two_Numbers_II.py --- LeetCode/0445_Add_Two_Numbers_II.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 LeetCode/0445_Add_Two_Numbers_II.py diff --git a/LeetCode/0445_Add_Two_Numbers_II.py b/LeetCode/0445_Add_Two_Numbers_II.py new file mode 100644 index 0000000..b0c6aea --- /dev/null +++ b/LeetCode/0445_Add_Two_Numbers_II.py @@ -0,0 +1,27 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def linkedListToInt(self, list_node, integer): + integer += str(list_node.val) + if list_node.next == None: + return int(integer) + else: + return self.linkedListToInt(list_node.next, integer) + + def intToLinkedList(self, integer): + integer = str(integer) + print(integer) + ll = [ListNode(int(integer[0]))] + for i in range(1, len(integer)): + ll.append(ListNode(int(integer[i]))) + ll[i - 1].next = ll[i] + return ll[0] + + def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: + first = self.linkedListToInt(l1, "") + second = self.linkedListToInt(l2, "") + summed = first + second + return self.intToLinkedList(summed) From 7b0bb1480f85a82158d5c2b6ced14741a3311a98 Mon Sep 17 00:00:00 2001 From: frank731 <38197177+frank731@users.noreply.github.com> Date: Sat, 10 Oct 2020 12:20:32 -0700 Subject: [PATCH 038/161] Delete 0445_Add_Two_Numbers_II.py --- LeetCode/0445_Add_Two_Numbers_II.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 LeetCode/0445_Add_Two_Numbers_II.py diff --git a/LeetCode/0445_Add_Two_Numbers_II.py b/LeetCode/0445_Add_Two_Numbers_II.py deleted file mode 100644 index b0c6aea..0000000 --- a/LeetCode/0445_Add_Two_Numbers_II.py +++ /dev/null @@ -1,27 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def linkedListToInt(self, list_node, integer): - integer += str(list_node.val) - if list_node.next == None: - return int(integer) - else: - return self.linkedListToInt(list_node.next, integer) - - def intToLinkedList(self, integer): - integer = str(integer) - print(integer) - ll = [ListNode(int(integer[0]))] - for i in range(1, len(integer)): - ll.append(ListNode(int(integer[i]))) - ll[i - 1].next = ll[i] - return ll[0] - - def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: - first = self.linkedListToInt(l1, "") - second = self.linkedListToInt(l2, "") - summed = first + second - return self.intToLinkedList(summed) From 58dd046fd3672f94ccc97406b317c40139db15ec Mon Sep 17 00:00:00 2001 From: Jeff Mikels Date: Sat, 10 Oct 2020 15:26:27 -0400 Subject: [PATCH 039/161] completed LeetCode 0080 --- ..._Remove_Duplicates_from_Sorted_Array_II.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 LeetCode/0080_Remove_Duplicates_from_Sorted_Array_II.py diff --git a/LeetCode/0080_Remove_Duplicates_from_Sorted_Array_II.py b/LeetCode/0080_Remove_Duplicates_from_Sorted_Array_II.py new file mode 100644 index 0000000..0d63cae --- /dev/null +++ b/LeetCode/0080_Remove_Duplicates_from_Sorted_Array_II.py @@ -0,0 +1,34 @@ +''' +https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ +''' + + +class Solution: + # we want to leave at most two of each element + def removeDuplicates(self, nums: list) -> int: + length = 0 + lastNum = None + lastLastNum = None + + # iterate in reverse order so that when we modify the list + # it doesn't affect the order of the unvisited elements + i = len(nums) - 1 + while i >= 0: + el = nums[i] + if el == lastLastNum: + del nums[i] + else: + length += 1 + lastLastNum = lastNum + lastNum = el + i -= 1 + + return length + + +if __name__ == '__main__': + solution = Solution() + input = [1, 1, 1, 2, 2, 3] + solution.removeDuplicates(input) + print(input) + print(len(input)) From 685d62020c59b4d0c6a7480514ba4cccbc8e2da2 Mon Sep 17 00:00:00 2001 From: michal-dbrnowski Date: Sat, 10 Oct 2020 21:33:39 +0200 Subject: [PATCH 040/161] Create 0202_Happy_Number.py --- LeetCode/0202_Happy_Number.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/0202_Happy_Number.py diff --git a/LeetCode/0202_Happy_Number.py b/LeetCode/0202_Happy_Number.py new file mode 100644 index 0000000..119036a --- /dev/null +++ b/LeetCode/0202_Happy_Number.py @@ -0,0 +1,13 @@ +class Solution(object): + def isHappy(self, n): + """ + :type n: int + :rtype: bool + """ + checked = [] + while n != 1 and n not in checked: + checked.append(n) + n = sum([int(i) ** 2 for i in str(n)]) + if n == 1: + return True + return False \ No newline at end of file From dc71cc81a60649f5b58cb3537461a2a7005899e7 Mon Sep 17 00:00:00 2001 From: abdulrahmannaser Date: Sat, 10 Oct 2020 23:37:37 +0200 Subject: [PATCH 041/161] [ADD] LeetCode: 1550 Three Consecutive Odds --- LeetCode/1550_Three_Consecutive_Odds.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 LeetCode/1550_Three_Consecutive_Odds.py diff --git a/LeetCode/1550_Three_Consecutive_Odds.py b/LeetCode/1550_Three_Consecutive_Odds.py new file mode 100644 index 0000000..2497f74 --- /dev/null +++ b/LeetCode/1550_Three_Consecutive_Odds.py @@ -0,0 +1,6 @@ +class Solution: + def threeConsecutiveOdds(self, arr: List[int]) -> bool: + ok = False + for i in range(0, len(arr) - 2): + ok |=arr[i] & 1 and arr[i + 1] & 1 and arr[i + 2] & 1 + return ok From 80bee539deecce47112f886df7c5bd277c4198ec Mon Sep 17 00:00:00 2001 From: abdulrahmannaser Date: Sun, 11 Oct 2020 01:43:11 +0200 Subject: [PATCH 042/161] [ADD] issue #640 solution --- ...ract_the_Product_and_Sum_of_Digits_of_an_Integer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 LeetCode/1281_Subtract_the_Product_and_Sum_of_Digits_of_an_Integer.py diff --git a/LeetCode/1281_Subtract_the_Product_and_Sum_of_Digits_of_an_Integer.py b/LeetCode/1281_Subtract_the_Product_and_Sum_of_Digits_of_an_Integer.py new file mode 100644 index 0000000..5fbfa4b --- /dev/null +++ b/LeetCode/1281_Subtract_the_Product_and_Sum_of_Digits_of_an_Integer.py @@ -0,0 +1,10 @@ +class Solution: + def subtractProductAndSum(self, n: int) -> int: + a = 1 + b = 0; + while(n): + a*=n%10 + b+=n%10 + n//=10 + return a - b + From 60aef69a15ed3eb1287215b2474465600c26d8ae Mon Sep 17 00:00:00 2001 From: abdulrahmannaser Date: Sun, 11 Oct 2020 01:46:47 +0200 Subject: [PATCH 043/161] [DELETE] 1550 solution because it's opened by someone else --- LeetCode/1550_Three_Consecutive_Odds.py | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 LeetCode/1550_Three_Consecutive_Odds.py diff --git a/LeetCode/1550_Three_Consecutive_Odds.py b/LeetCode/1550_Three_Consecutive_Odds.py deleted file mode 100644 index 2497f74..0000000 --- a/LeetCode/1550_Three_Consecutive_Odds.py +++ /dev/null @@ -1,6 +0,0 @@ -class Solution: - def threeConsecutiveOdds(self, arr: List[int]) -> bool: - ok = False - for i in range(0, len(arr) - 2): - ok |=arr[i] & 1 and arr[i + 1] & 1 and arr[i + 2] & 1 - return ok From 420cfab54fc15c033edb79bf7cdecbecdd8a41b7 Mon Sep 17 00:00:00 2001 From: Alexey Ilyukhov Date: Sun, 11 Oct 2020 03:16:46 +0300 Subject: [PATCH 044/161] fix --- LeetCode/1340_Jump_Game_V.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LeetCode/1340_Jump_Game_V.py b/LeetCode/1340_Jump_Game_V.py index 1094f4d..9a8a911 100644 --- a/LeetCode/1340_Jump_Game_V.py +++ b/LeetCode/1340_Jump_Game_V.py @@ -1,5 +1,5 @@ -class Solution(object): - def maxJumps(self, arr, d): +class Solution: + def maxJumps(self, arr: List[int], d: int) -> int: """ :type arr: List[int] :type d: int @@ -9,7 +9,7 @@ def maxJumps(self, arr, d): dp = [1] * len(arr) for i, _ in sorted(enumerate(arr), key=lambda x: x[1]): - max_h = None + max_h = 0 for j in range(i - 1, max(i - d - 1, -1), -1): max_h = max(max_h, arr[j]) if max_h < arr[i]: @@ -17,7 +17,7 @@ def maxJumps(self, arr, d): else: break - max_h = None + max_h = 0 for j in range(i + 1, min(i + d + 1, len(arr))): max_h = max(max_h, arr[j]) if max_h < arr[i]: From 7514172e9077db3392e178ee95899b1e8e8331dd Mon Sep 17 00:00:00 2001 From: Alexey Ilyukhov Date: Sun, 11 Oct 2020 03:17:21 +0300 Subject: [PATCH 045/161] fix --- LeetCode/1340_Jump_Game_V.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/LeetCode/1340_Jump_Game_V.py b/LeetCode/1340_Jump_Game_V.py index 9a8a911..837a615 100644 --- a/LeetCode/1340_Jump_Game_V.py +++ b/LeetCode/1340_Jump_Game_V.py @@ -1,11 +1,5 @@ class Solution: def maxJumps(self, arr: List[int], d: int) -> int: - """ - :type arr: List[int] - :type d: int - :rtype: int - """ - dp = [1] * len(arr) for i, _ in sorted(enumerate(arr), key=lambda x: x[1]): From 151b10d36d0d00a74fee924ce9deae7469150407 Mon Sep 17 00:00:00 2001 From: Jared Gillespie Date: Sat, 10 Oct 2020 18:10:38 -0700 Subject: [PATCH 046/161] Add 589. N-ary Tree Preorder Traversal https://leetcode.com/submissions/detail/205318247/ --- LeetCode/589_Nary_Tree_Preorder_Traversal.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 LeetCode/589_Nary_Tree_Preorder_Traversal.py diff --git a/LeetCode/589_Nary_Tree_Preorder_Traversal.py b/LeetCode/589_Nary_Tree_Preorder_Traversal.py new file mode 100644 index 0000000..14035ce --- /dev/null +++ b/LeetCode/589_Nary_Tree_Preorder_Traversal.py @@ -0,0 +1,15 @@ +class Solution(object): + def preorder(self, root): + """ + :type root: Node + :rtype: List[int] + """ + def traverse(root): + if not root: return + ret.append(root.val) + for child in root.children: + traverse(child) + + ret = [] + traverse(root) + return ret From 9364f11529d290139fa43b3b2085b3ade9feebdd Mon Sep 17 00:00:00 2001 From: Bhawesh Bhansali Date: Sun, 11 Oct 2020 08:44:37 +0530 Subject: [PATCH 047/161] Update for Python3 --- LeetCode/1589-maximum-sum-obtained-of-any-permutation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py b/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py index 9735428..4037231 100644 --- a/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py +++ b/LeetCode/1589-maximum-sum-obtained-of-any-permutation.py @@ -14,7 +14,7 @@ def addmod(a, b, mod): # avoid overflow in other languages if mod-a <= b: b -= mod return a+b - + def mulmod(a, b, mod): # avoid overflow in other languages a %= mod b %= mod @@ -35,12 +35,12 @@ def mulmod(a, b, mod): # avoid overflow in other languages count[start] += 1 if end+1 < len(count): count[end+1] -= 1 - for i in xrange(1, len(count)): + for i in range(1, len(count)): count[i] += count[i-1] nums.sort() count.sort() result = 0 - for i, (num, c) in enumerate(itertools.izip(nums, count)): + for i, (num, c) in enumerate(zip(nums, count)): # result = addmod(result, mulmod(num, c, MOD), MOD) result = (result+num*c)%MOD return result From c8cebaa51bed35fb8fb7afd1e4a7283dee80539c Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 10:12:46 +0530 Subject: [PATCH 048/161] Add files via upload This is an issue_template submitting a leetcode problem --- .github/ISSUE_TEMPLATE/Leetcodesubmission.md | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Leetcodesubmission.md diff --git a/.github/ISSUE_TEMPLATE/Leetcodesubmission.md b/.github/ISSUE_TEMPLATE/Leetcodesubmission.md new file mode 100644 index 0000000..dd20366 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Leetcodesubmission.md @@ -0,0 +1,36 @@ +--- +name: Rotate image +about: Use this Template to submit a new LeetCode Problem +title: 0048_Rotate_Image +labels: 'hacktoberfest' +assignees: 'grpnpraveen' + +--- + +## Description of the Problem +You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). + +You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. + +## Code +``` +class Solution { +public: + void rotate(vector>& matrix) { + + int n = matrix.size(); + for(int i=0;i Date: Sun, 11 Oct 2020 10:13:59 +0530 Subject: [PATCH 049/161] Add files via upload A problem submitted --- LeetCode/0048_Rotate_Image.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 LeetCode/0048_Rotate_Image.py diff --git a/LeetCode/0048_Rotate_Image.py b/LeetCode/0048_Rotate_Image.py new file mode 100644 index 0000000..918e60e --- /dev/null +++ b/LeetCode/0048_Rotate_Image.py @@ -0,0 +1,9 @@ +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + for i in range(len(matrix)): + for j in range(i,len(matrix)): + if i != j: + matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j] + for each in matrix: + each.reverse() + return matrix \ No newline at end of file From 9aa1857316b4479a11e60ab1853268f1dcc32c17 Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 10:26:06 +0530 Subject: [PATCH 050/161] Delete Leetcodesubmission.md --- .github/ISSUE_TEMPLATE/Leetcodesubmission.md | 36 -------------------- 1 file changed, 36 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Leetcodesubmission.md diff --git a/.github/ISSUE_TEMPLATE/Leetcodesubmission.md b/.github/ISSUE_TEMPLATE/Leetcodesubmission.md deleted file mode 100644 index dd20366..0000000 --- a/.github/ISSUE_TEMPLATE/Leetcodesubmission.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -name: Rotate image -about: Use this Template to submit a new LeetCode Problem -title: 0048_Rotate_Image -labels: 'hacktoberfest' -assignees: 'grpnpraveen' - ---- - -## Description of the Problem -You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). - -You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. - -## Code -``` -class Solution { -public: - void rotate(vector>& matrix) { - - int n = matrix.size(); - for(int i=0;i Date: Sun, 11 Oct 2020 10:27:59 +0530 Subject: [PATCH 051/161] Add files via upload An issue template regarding a 0048_problem --- .github/ISSUE_TEMPLATE/Leetcodesubmission.md | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Leetcodesubmission.md diff --git a/.github/ISSUE_TEMPLATE/Leetcodesubmission.md b/.github/ISSUE_TEMPLATE/Leetcodesubmission.md new file mode 100644 index 0000000..11ab739 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Leetcodesubmission.md @@ -0,0 +1,29 @@ +--- +name: Rotate image +about: Use this Template to submit a new LeetCode Problem +title: 0048_Rotate_Image +labels: 'hacktoberfest' +assignees: 'grpnpraveen' + +--- + +## Description of the Problem +You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). + +You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. + +## Code +``` +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + for i in range(len(matrix)): + for j in range(i,len(matrix)): + if i != j: + matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j] + for each in matrix: + each.reverse() + return matrix +``` + +## Link To The LeetCode Problem +[LeetCode](https://leetcode.com/problems/rotate-image/) From 0f0034e83d6f01690d4b6058b37bb945ca20b510 Mon Sep 17 00:00:00 2001 From: sailok Date: Sun, 11 Oct 2020 10:38:23 +0530 Subject: [PATCH 052/161] Adding 0106 - Construct Binary Tree from Inorder and Postorder Traversal --- ...ee_from_Inorder_and_Postorder_Traversal.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LeetCode/0106_Construct_Binary_Tree_from_Inorder_and_Postorder_Traversal.py diff --git a/LeetCode/0106_Construct_Binary_Tree_from_Inorder_and_Postorder_Traversal.py b/LeetCode/0106_Construct_Binary_Tree_from_Inorder_and_Postorder_Traversal.py new file mode 100644 index 0000000..4157914 --- /dev/null +++ b/LeetCode/0106_Construct_Binary_Tree_from_Inorder_and_Postorder_Traversal.py @@ -0,0 +1,22 @@ +class Solution: + def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode: + return self.helperFunc(inorder, postorder, 0, len(inorder)-1, len(postorder)-1) + def helperFunc(self, inorder: List[int], postorder: List[int], left: int, right: int, postIndex: int) -> TreeNode: + # checks if there is node required else puts null in the binary tree + if postIndex == -1: + return + # creating the root of the subtree from the value present at current postIndex + root = TreeNode(postorder[postIndex]) + # we find the root's value in order to divide them into left and right subtree + x = 0 + for i in range(len(inorder)): + if root.val == inorder[i]: + x = i + # finding corresponding values that are roots for left and right subtrees or assign -1 + right_post = -1 if abs(right - x) == 0 else postIndex - 1 + left_post = -1 if abs(left - x) == 0 else postIndex -1 - abs(right - x) + # calling recursively helperFunc for left and right subtrees + root.left = self.helperFunc(inorder, postorder, left, x-1, left_post) + root.right = self.helperFunc(inorder, postorder, x+1, right, right_post) + return root + \ No newline at end of file From 8653fa59d90f4be4d0d72a105c760f89940b7d4e Mon Sep 17 00:00:00 2001 From: Anshul Gautam Date: Sun, 11 Oct 2020 12:13:26 +0530 Subject: [PATCH 053/161] added solution for issue 0138 --- .DS_Store | Bin 0 -> 8196 bytes .../0138_Copy_List_with_Random_Pointer.py | 31 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 .DS_Store create mode 100644 LeetCode/0138_Copy_List_with_Random_Pointer.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2b814e5fb2bf3fee468e4839f097ac358da063b3 GIT binary patch literal 8196 zcmeHMTWl0n7(U-pV1|h>t(A+i*)0W1u!iMg5izjrwrDTVhHYuNwVmA=Vd8XVnVH>! zO=C40jS%$38;$bdHKIO=w@$#T1@Iqot{Lh>zp*Q1`Au?xk&VSDN zFQ@-E-$lADuEhjK(n;m#o38N!tj-cS&%PJYS2 zoFOe_)J6zI2uwwQZy$-ZF@rw-jraGw<>X0sHD9z$&rhYkM{HKb>^XBKd7dIG^A-6( z?vOK>^EJQZWi+=>U79m>Bd@vLrtTl=H0&nJC>wUW+ot)3yN?@pI*vsKqOaw5o5o-3{v-hKFTIT2i-tS8wTw6DLRCc=N5d&z=i>7{WIRs}$qw?Rn}=fyDC4 zSpi9GY#fqHH$bA?7H?^7+p)8~PgP5vvCFVD-z*!Al)TrcF7PP*=7M8)xJH@M?k+f1 zX}~5;WkItFB{DX)Sys+`R9F{W$Fe#c&-6{l-qYh7M|`g1fhMSW_Ii%%XMiwP%EpHYGq+}+4Ri3WpoYlr?yA)3Wlwl z_QAdM9Bkiw*fddBpt5GRD|2Bkq# zb-ByZ@`fd*HYuAWwN>sei*&_gwX#)`dkW6L043vzxlFuKQoodX`ND0Q=eHLPo7U#3 zZLf*P_we~`x^C!_LvjS&}z&`U1XQp@9YnDg@8NxXfRAw&=kPhczy!_UbzpE=sOgy=KFv zEt%_dn8bh^nHZ2yuq$BQIIDt(K9R~|M<|IdBBya=rj4P_<(o(vk^M&Gy~h5+Y|O(VB#E~5XuuXCZ5EAa!cKHx7jo#t0rU}l^F&|^ zHi|e*Bp$*r9>WM8$Fn$26n+lR;}xRtt9T8k@DAR^X(IC(qVgyB6rT~9zrlC7G>N)x z6RC^K(^0pab8XA950Y-2@)O;n5o5Ci2#fjsziH;*|0Ad(1R@0f#|WUJG1r)(1ZR3x z^1F7DYClz8xZQ}5feSUsLo&S@*#75_T JK*(F9`5TA7SFiv8 literal 0 HcmV?d00001 diff --git a/LeetCode/0138_Copy_List_with_Random_Pointer.py b/LeetCode/0138_Copy_List_with_Random_Pointer.py new file mode 100644 index 0000000..a2f9787 --- /dev/null +++ b/LeetCode/0138_Copy_List_with_Random_Pointer.py @@ -0,0 +1,31 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): + self.val = int(x) + self.next = next + self.random = random +""" + +def solve(head): + d = {} + h = head + while(h): + copy = Node(h.val) + d[h] = copy + h = h.next + h = head + while(h): + copy = d[h] + if(h.next): + copy.next = d[h.next] + if(h.random): + copy.random = d[h.random] + h = h.next + if(head): + return d[head] + return None + +class Solution: + def copyRandomList(self, head: 'Node') -> 'Node': + return solve(head) From 3f4d6d020b539fea9e7cfd192276642684645689 Mon Sep 17 00:00:00 2001 From: Anshul Gautam Date: Sun, 11 Oct 2020 12:21:54 +0530 Subject: [PATCH 054/161] added solution for issue 0338 --- LeetCode/0338_Counting_Bits.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LeetCode/0338_Counting_Bits.py diff --git a/LeetCode/0338_Counting_Bits.py b/LeetCode/0338_Counting_Bits.py new file mode 100644 index 0000000..57d8397 --- /dev/null +++ b/LeetCode/0338_Counting_Bits.py @@ -0,0 +1,12 @@ +def solve(n): + dp = [0]*(n+1) + offset = 1 + for i in range(1,n+1): + if(not i&(i-1)): + offset = i + dp[i] = dp[i-offset] + 1 + return dp + +class Solution: + def countBits(self, num: int) -> List[int]: + return solve(num) From c381bae9175ee1709224922a4dad9793821c769d Mon Sep 17 00:00:00 2001 From: Tushar Sethi Date: Sun, 11 Oct 2020 12:26:34 +0530 Subject: [PATCH 055/161] Added 1299_Replace_Elements_with_Greatest_Elements_oon_Right_Side.py file --- ...lace_Elements_with_Greatest_Elements_on_Right_Side.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py diff --git a/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py b/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py new file mode 100644 index 0000000..161532f --- /dev/null +++ b/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py @@ -0,0 +1,9 @@ +class Solution(object): + def replaceElements(self, arr): + arr1 = [] + for i in range(len(arr)): + if i==len(arr)-1: + arr1.append(-1) + else: + arr1.append(max(arr[i+1:])) + return arr1 \ No newline at end of file From ee17de30953a4cc03ad7be856e19587a6a12235a Mon Sep 17 00:00:00 2001 From: Tushar Sethi Date: Sun, 11 Oct 2020 12:49:18 +0530 Subject: [PATCH 056/161] Added 1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py --- ...eplace_Elements_with_Greatest_Elements_on_Right_Side.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py b/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py index 161532f..074272b 100644 --- a/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py +++ b/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py @@ -1,9 +1,8 @@ class Solution(object): def replaceElements(self, arr): - arr1 = [] for i in range(len(arr)): if i==len(arr)-1: - arr1.append(-1) + arr[i] = -1 else: - arr1.append(max(arr[i+1:])) - return arr1 \ No newline at end of file + arr[i] = max(arr[i+1:]) + return \ No newline at end of file From 870338990c481b9f3ab74bc040bc7e7d2b0479a2 Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 13:00:23 +0530 Subject: [PATCH 057/161] Add files via upload An issue template related to 0014 problem --- .github/ISSUE_TEMPLATE/Leetcodesubmission2.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Leetcodesubmission2.md diff --git a/.github/ISSUE_TEMPLATE/Leetcodesubmission2.md b/.github/ISSUE_TEMPLATE/Leetcodesubmission2.md new file mode 100644 index 0000000..30f2c03 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Leetcodesubmission2.md @@ -0,0 +1,35 @@ +--- +name: Longest Common Prefix +title: 0014_ Longest_Common_Prefix +labels: 'hacktoberfest' +assignees: 'grpnpraveen' + +--- + +## Description of the Problem +Write a function to find the longest common prefix string amongst an array of strings. + +If there is no common prefix, return an empty string "". + +## Code +``` +class Solution: + def longestCommonPrefix(self, strs): + """ + :type strs: List[str] + :rtype: str + """ + if len(strs) == 0: + return '' + res = '' + strs = sorted(strs) + for i in strs[0]: + if strs[-1].startswith(res+i): + res += i + else: + break + return res +``` + +## Link To The LeetCode Problem +[LeetCode](https://leetcode.com/problems/longest-common-prefix/) From 3cc84c6bff6326c0a4f0078a2f8b6f59ca773c39 Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 13:01:13 +0530 Subject: [PATCH 058/161] Add files via upload 0014_LONGEST_common_prefix problem added to the leetcode --- LeetCode/0014_Longest_common_Prefix.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 LeetCode/0014_Longest_common_Prefix.py diff --git a/LeetCode/0014_Longest_common_Prefix.py b/LeetCode/0014_Longest_common_Prefix.py new file mode 100644 index 0000000..de0859d --- /dev/null +++ b/LeetCode/0014_Longest_common_Prefix.py @@ -0,0 +1,16 @@ +class Solution: + def longestCommonPrefix(self, strs): + """ + :type strs: List[str] + :rtype: str + """ + if len(strs) == 0: + return '' + res = '' + strs = sorted(strs) + for i in strs[0]: + if strs[-1].startswith(res+i): + res += i + else: + break + return res \ No newline at end of file From 686d59c33eca11e1e66d951314a3d92d60f4f361 Mon Sep 17 00:00:00 2001 From: Tushar Sethi Date: Sun, 11 Oct 2020 13:06:43 +0530 Subject: [PATCH 059/161] Added 1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py --- ...299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py b/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py index 074272b..f3134cf 100644 --- a/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py +++ b/LeetCode/1299_Replace_Elements_with_Greatest_Elements_on_Right_Side.py @@ -5,4 +5,4 @@ def replaceElements(self, arr): arr[i] = -1 else: arr[i] = max(arr[i+1:]) - return \ No newline at end of file + return arr \ No newline at end of file From 4aade0a57ec5ea58702aa250713c88398b6942d4 Mon Sep 17 00:00:00 2001 From: Varisht Date: Sun, 11 Oct 2020 13:09:33 +0530 Subject: [PATCH 060/161] Added code for LRU Cache --- LeetCode/0146_LRU_Cache.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 LeetCode/0146_LRU_Cache.py diff --git a/LeetCode/0146_LRU_Cache.py b/LeetCode/0146_LRU_Cache.py new file mode 100644 index 0000000..7a3f01d --- /dev/null +++ b/LeetCode/0146_LRU_Cache.py @@ -0,0 +1,28 @@ +class LRUCache: + + def __init__(self, capacity: int): + self.capacity = capacity + self.cache = collections.OrderedDict() + + + def get(self, key: int) -> int: + if key not in self.cache: + return -1 + else: + val = self.cache[key] + del self.cache[key] + self.cache[key] = val + return val + + def put(self, key: int, value: int) -> None: + if key in self.cache: + del self.cache[key] + elif len(self.cache) == self.capacity: + self.cache.popitem(last=False) + self.cache[key] = value + + +# Your LRUCache object will be instantiated and called as such: +# obj = LRUCache(capacity) +# param_1 = obj.get(key) +# obj.put(key,value) From acfba5342bf4c64b597bf08abb534afd9e68513e Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 13:14:10 +0530 Subject: [PATCH 061/161] Delete Leetcodesubmission2.md --- .github/ISSUE_TEMPLATE/Leetcodesubmission2.md | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Leetcodesubmission2.md diff --git a/.github/ISSUE_TEMPLATE/Leetcodesubmission2.md b/.github/ISSUE_TEMPLATE/Leetcodesubmission2.md deleted file mode 100644 index 30f2c03..0000000 --- a/.github/ISSUE_TEMPLATE/Leetcodesubmission2.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: Longest Common Prefix -title: 0014_ Longest_Common_Prefix -labels: 'hacktoberfest' -assignees: 'grpnpraveen' - ---- - -## Description of the Problem -Write a function to find the longest common prefix string amongst an array of strings. - -If there is no common prefix, return an empty string "". - -## Code -``` -class Solution: - def longestCommonPrefix(self, strs): - """ - :type strs: List[str] - :rtype: str - """ - if len(strs) == 0: - return '' - res = '' - strs = sorted(strs) - for i in strs[0]: - if strs[-1].startswith(res+i): - res += i - else: - break - return res -``` - -## Link To The LeetCode Problem -[LeetCode](https://leetcode.com/problems/longest-common-prefix/) From 8061c39ed126c8765daa2cad521a6a50429aef94 Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 13:14:24 +0530 Subject: [PATCH 062/161] Delete Leetcodesubmission.md --- .github/ISSUE_TEMPLATE/Leetcodesubmission.md | 29 -------------------- 1 file changed, 29 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Leetcodesubmission.md diff --git a/.github/ISSUE_TEMPLATE/Leetcodesubmission.md b/.github/ISSUE_TEMPLATE/Leetcodesubmission.md deleted file mode 100644 index 11ab739..0000000 --- a/.github/ISSUE_TEMPLATE/Leetcodesubmission.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -name: Rotate image -about: Use this Template to submit a new LeetCode Problem -title: 0048_Rotate_Image -labels: 'hacktoberfest' -assignees: 'grpnpraveen' - ---- - -## Description of the Problem -You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). - -You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. - -## Code -``` -class Solution: - def rotate(self, matrix: List[List[int]]) -> None: - for i in range(len(matrix)): - for j in range(i,len(matrix)): - if i != j: - matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j] - for each in matrix: - each.reverse() - return matrix -``` - -## Link To The LeetCode Problem -[LeetCode](https://leetcode.com/problems/rotate-image/) From 3a899910b9a0ed6dd1d3b2ba237f9c1cea64d205 Mon Sep 17 00:00:00 2001 From: sailok Date: Sun, 11 Oct 2020 13:26:35 +0530 Subject: [PATCH 063/161] Adding 0208 Implement Trie --- LeetCode/0208_Implement_Trie.py.py | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 LeetCode/0208_Implement_Trie.py.py diff --git a/LeetCode/0208_Implement_Trie.py.py b/LeetCode/0208_Implement_Trie.py.py new file mode 100644 index 0000000..2393881 --- /dev/null +++ b/LeetCode/0208_Implement_Trie.py.py @@ -0,0 +1,58 @@ +class TrieNode: + def __init__(self, val): + self.val = val + self.isEnd = False + self.children = [None for i in range(26)] +class Trie: + def __init__(self): + """ + Initialize your data structure here. + """ + self.root = TrieNode('*') + + + def insert(self, word: str) -> None: + """ + Inserts a word into the trie. + """ + node = self.root + for c in word: + x = ord(c) - ord('a') + if node.children[x] is None: + node.children[x] = TrieNode(c) + node = node.children[x] + node.isEnd = True + + def search(self, word: str) -> bool: + """ + Returns if the word is in the trie. + """ + node = self.root + for c in word: + x = ord(c) - ord('a') + if node.children[x] is not None: + node = node.children[x] + else: + return False + return node.isEnd + + + def startsWith(self, prefix: str) -> bool: + """ + Returns if there is any word in the trie that starts with the given prefix. + """ + node = self.root + for c in prefix: + x = ord(c) - ord('a') + if node.children[x] is not None: + node = node.children[x] + else: + return False + return True + + +# Your Trie object will be instantiated and called as such: +# obj = Trie() +# obj.insert(word) +# param_2 = obj.search(word) +# param_3 = obj.startsWith(prefix) \ No newline at end of file From 42bce83a33828e4cc60cc9af663f8696bb4a312c Mon Sep 17 00:00:00 2001 From: Tushar Sethi Date: Sun, 11 Oct 2020 13:30:21 +0530 Subject: [PATCH 064/161] Added 1436_Destination_City --- LeetCode/1436_Destination_City.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 LeetCode/1436_Destination_City.py diff --git a/LeetCode/1436_Destination_City.py b/LeetCode/1436_Destination_City.py new file mode 100644 index 0000000..6537894 --- /dev/null +++ b/LeetCode/1436_Destination_City.py @@ -0,0 +1,10 @@ +class Solution(object): + def destCity(self, paths): + origin, destination = [], [] + for p in paths: + origin.append(p[0]) + destination.append(p[1]) + + for d in destination: + if d not in origin : + return d \ No newline at end of file From 3b41c712b16e441c6ce17109933b593bd6876619 Mon Sep 17 00:00:00 2001 From: SushanthReddyManda Date: Sun, 11 Oct 2020 14:14:23 +0530 Subject: [PATCH 065/161] Create 1544_Make_String_Great --- LeetCode/1544_Make_string_great.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LeetCode/1544_Make_string_great.py diff --git a/LeetCode/1544_Make_string_great.py b/LeetCode/1544_Make_string_great.py new file mode 100644 index 0000000..be04276 --- /dev/null +++ b/LeetCode/1544_Make_string_great.py @@ -0,0 +1,18 @@ +def finder(s): + a =0 + for i in range(len(s) -1): + if abs(ord(s[i]) - ord(s[i+1])) == 32 : + del s[i] + del s[i] + a =1 + break + if a == 0 : + return s + else: + return finder(s) + +class Solution: + def makeGood(self, s: str) -> str: + s = list(s) + h = finder(s) + return ("".join(h)) \ No newline at end of file From cd05aa835a7e4c3d233af412d438d9097091de4e Mon Sep 17 00:00:00 2001 From: praneshulleri Date: Sun, 11 Oct 2020 14:31:49 +0530 Subject: [PATCH 066/161] Maximum Binary Tree --- LeetCode/0654_Maximum_Binary_Tree.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/0654_Maximum_Binary_Tree.py diff --git a/LeetCode/0654_Maximum_Binary_Tree.py b/LeetCode/0654_Maximum_Binary_Tree.py new file mode 100644 index 0000000..6fc4128 --- /dev/null +++ b/LeetCode/0654_Maximum_Binary_Tree.py @@ -0,0 +1,13 @@ +class Solution: + def constructMaximumBinaryTree(self, nums: List[int]) -> TreeNode: + def helper(nums, root): + if not nums: + return None + if nums: + root = TreeNode(max(nums)) + ind=nums.index(max(nums)) + root.left= helper(nums[:ind],root) + root.right=helper(nums[ind+1:],root) + return root + root=TreeNode(0) + return helper(nums,root) From 905c4aceafc20bb6a5e5cb5393ab7803650fafb5 Mon Sep 17 00:00:00 2001 From: Vinit-Dantkale Date: Sun, 11 Oct 2020 15:06:36 +0530 Subject: [PATCH 067/161] Adding solution to 1446_consecutive_characters --- LeetCode/1446_consecutive_characters.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 LeetCode/1446_consecutive_characters.py diff --git a/LeetCode/1446_consecutive_characters.py b/LeetCode/1446_consecutive_characters.py new file mode 100644 index 0000000..c29914c --- /dev/null +++ b/LeetCode/1446_consecutive_characters.py @@ -0,0 +1,10 @@ +class Solution: + def maxPower(self, s: str) -> int: + maxlen,currlen=1,1 + for i in range(1,len(s)): + if(s[i]==s[i-1]): + currlen=currlen+1 + maxlen=max(maxlen,currlen) + else: + currlen=1 + return maxlen \ No newline at end of file From 489f4f45c0d3f5ec629397b828ba2c57465d4b3a Mon Sep 17 00:00:00 2001 From: Andrey Zakharov Date: Sun, 11 Oct 2020 14:06:23 +0300 Subject: [PATCH 068/161] Create 0942_DI_String_Match.py 942. DI String Match --- LeetCode/0942_DI_String_Match.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/0942_DI_String_Match.py diff --git a/LeetCode/0942_DI_String_Match.py b/LeetCode/0942_DI_String_Match.py new file mode 100644 index 0000000..60eeb14 --- /dev/null +++ b/LeetCode/0942_DI_String_Match.py @@ -0,0 +1,13 @@ +class Solution: + def diStringMatch(self, S: str) -> List[int]: + mx = 0 + mn = 0 + res = [0] * (len(S) + 1) + for i in range(len(S)): + if S[i] == "I": + res[i + 1] = mx + 1 + mx += 1 + else: + res[i + 1] = mn - 1 + mn -= 1 + return [x - mn for x in res] From b2a584c29c044e2a3ea279d93904b484ac6ed694 Mon Sep 17 00:00:00 2001 From: grpnpraveen Date: Sun, 11 Oct 2020 16:41:36 +0530 Subject: [PATCH 069/161] Add files via upload 0067_Add_Binary added to leetcode --- LeetCode/0067_Add_Binary.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 LeetCode/0067_Add_Binary.py diff --git a/LeetCode/0067_Add_Binary.py b/LeetCode/0067_Add_Binary.py new file mode 100644 index 0000000..529e8b1 --- /dev/null +++ b/LeetCode/0067_Add_Binary.py @@ -0,0 +1,4 @@ +class Solution: + def addBinary(self, a: str, b: str) -> str: + sum = int(a,2) + int(b,2) + return bin(sum)[2:] \ No newline at end of file From 346c1ce8b4fcaa5ffb55aa9dc2cad10346586470 Mon Sep 17 00:00:00 2001 From: Rakshaa Viswanathan <46165429+rakshaa2000@users.noreply.github.com> Date: Sun, 11 Oct 2020 16:44:03 +0530 Subject: [PATCH 070/161] Created 0092_Decode_Ways.py --- LeetCode/0092_Decode_Ways.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 LeetCode/0092_Decode_Ways.py diff --git a/LeetCode/0092_Decode_Ways.py b/LeetCode/0092_Decode_Ways.py new file mode 100644 index 0000000..0f0c382 --- /dev/null +++ b/LeetCode/0092_Decode_Ways.py @@ -0,0 +1,40 @@ +''' +Problem:- +A message containing letters from A-Z is being encoded to numbers using the following mapping: + +'A' -> 1 +'B' -> 2 +... +'Z' -> 26 +Given a non-empty string containing only digits, determine the total number of ways to decode it. + +The answer is guaranteed to fit in a 32-bit integer. + +Example 1: + +Input: s = "12" +Output: 2 +Explanation: It could be decoded as "AB" (1 2) or "L" (12). + +Example 2: + +Input: s = "226" +Output: 3 +Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6). +''' + +class Solution: + def numDecodings(self, s: str) -> int: + @lru_cache(None) + def dp(i): + if i == len(s): + return 1 + ans = 0 + if s[i] != '0': + ans += dp(i+1) + if s[i] == '1' and i+1< len(s): + ans += dp(i+2) + if s[i] == '2' and i+1 < len(s) and s[i+1] <= '6': + ans += dp(i+2) + return ans + return dp(0) From ec8d7539bf1821b6a5b7d08d060561b77550e99d Mon Sep 17 00:00:00 2001 From: Rakshaa Viswanathan <46165429+rakshaa2000@users.noreply.github.com> Date: Sun, 11 Oct 2020 16:54:13 +0530 Subject: [PATCH 071/161] Create 0094_Binary_Tree_Inorder_Traversal.py --- .../0094_Binary_Tree_Inorder_Traversal.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LeetCode/0094_Binary_Tree_Inorder_Traversal.py diff --git a/LeetCode/0094_Binary_Tree_Inorder_Traversal.py b/LeetCode/0094_Binary_Tree_Inorder_Traversal.py new file mode 100644 index 0000000..d1b9e92 --- /dev/null +++ b/LeetCode/0094_Binary_Tree_Inorder_Traversal.py @@ -0,0 +1,19 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def inorderTraversal(self, root: TreeNode) -> List[int]: + res = [] + myStack = [] + curr = root + while len(myStack) or curr is not None: + while curr is not None: + myStack.append(curr) + curr = curr.left + curr = myStack.pop() + res.append(curr.val) + curr = curr.right + return res From ff648a629301b373274fff05e77fce49835257d4 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:14:55 +0530 Subject: [PATCH 072/161] Added Script to check and comment --- .github/workflows/leetcodeChecker.yml | 26 +++ codechecker.py | 51 ++++- leetcodeChecker.py | 311 ++++++++++++++++++++++++++ 3 files changed, 384 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/leetcodeChecker.yml create mode 100644 leetcodeChecker.py diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml new file mode 100644 index 0000000..09e8828 --- /dev/null +++ b/.github/workflows/leetcodeChecker.yml @@ -0,0 +1,26 @@ +name: py + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # - name: checkout repo content # checkout is unecessary + # uses: actions/checkout@v2 + - name: setup python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: execute checker script + run: | + python codechecker.py + with: + github-token: ${{ github.token }} + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }} + leetcode-session: ${{ secrets.LEETCODE_SESSION }} + diff --git a/codechecker.py b/codechecker.py index c286bf9..2c1c6b8 100644 --- a/codechecker.py +++ b/codechecker.py @@ -5,6 +5,38 @@ load_dotenv(dotenv_path='sample.env') +def get_submissions(slug): + url = "https://leetcode-cn.com/graphql" + params = {'operationName': "Submissions", + 'variables': {"offset": 0, "limit": 20, "lastKey": '', "questionSlug": slug}, + 'query': '''query Submissions($offset: Int!, $limit: Int!, $lastKey: String, $questionSlug: String!) { + submissionList(offset: $offset, limit: $limit, lastKey: $lastKey, questionSlug: $questionSlug) { + lastKey + hasNext + submissions { + id + statusDisplay + lang + runtime + timestamp + url + isPending + __typename + } + __typename + } + }''' + } + + json_data = json.dumps(params).encode('utf8') + + headers = {'User-Agent': user_agent, 'Connection': 'keep-alive', 'Referer': 'https://leetcode-cn.com/accounts/login/', + "Content-Type": "application/json"} + resp = session.post(url, data=json_data, headers=headers, timeout=10) + content = resp.json() + for submission in content['data']['submissionList']['submissions']: + print(submission) + # load details from ENV repo_name = os.getenv("REPO_NAME") access_token = os.getenv("GITHUB_ACCESS_TOKEN") @@ -26,7 +58,7 @@ for i in all_files: if i.filename[-3:] == ".py": file_url = i.raw_url - problem_name = i.filename.lower() + problem_name = i.filename[9:].lower() # parse question id and problem name question_id = int(problem_name[0:4]) @@ -42,20 +74,31 @@ headers = { "Origin": "https://leetcode.com", "content-type": "application/json", - "X-CSRFToken": leetcode_csrf_token, - "Referer": leetcode_submission_url, + "Referer": "https://leetcode.com/problems/two-sum/submissions/", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0", # "Cookie": f"csrftoken={leetcode_csrf_token};LEETCODE_SESSION={leetcode_session_token}", } + +headers = { + 'Connection': 'keep-alive', + 'Content-Type': 'application/json', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36', + 'Referer': 'https://leetcode.com/accounts/login/', + "origin": "https://leetcode.com" +} + cookies = { "csrftoken": leetcode_csrf_token, "LEETCODE_SESSION": leetcode_session_token, } body = {"question_id": str(question_id), "lang": language, "typed_code": code} +leetcode_submission_url2 = f"https://leetcode.com/api/problems/all" +leetcode_submission_url3 = f"https://leetcode.com/accounts/login/" # send request +sub = requests.get(leetcode_submission_url2, headers=headers, data=body, cookies=cookies) submit = requests.post( - leetcode_submission_url, headers=headers, data=body, cookies=cookies + leetcode_submission_url3, headers=headers, cookies=cookies ) print(submit.status_code) diff --git a/leetcodeChecker.py b/leetcodeChecker.py new file mode 100644 index 0000000..873d7ac --- /dev/null +++ b/leetcodeChecker.py @@ -0,0 +1,311 @@ +import requests, os, re, json, time +from github import Github +import browser_cookie3 +import keyring, pickle +from bs4 import BeautifulSoup + +from dotenv import load_dotenv + +load_dotenv(dotenv_path='sample.env') + +LC_BASE = 'https://leetcode.com' +LC_CSRF = LC_BASE + '/ensure_csrf/' +LC_LOGIN = LC_BASE + '/accounts/login/' +LC_GRAPHQL = LC_BASE + '/graphql' +LC_CATEGORY_PROBLEMS = LC_BASE + '/api/problems/{category}' +LC_PROBLEM = LC_BASE + '/problems/{slug}/description' +LC_TEST = LC_BASE + '/problems/{slug}/interpret_solution/' +LC_SUBMIT = LC_BASE + '/problems/{slug}/submit/' +LC_SUBMISSIONS = LC_BASE + '/api/submissions/{slug}' +LC_SUBMISSION = LC_BASE + '/submissions/detail/{submission}/' +LC_CHECK = LC_BASE + '/submissions/detail/{submission}/check/' +LC_PROBLEM_SET_ALL = LC_BASE + '/problemset/all/' +LC_PROGRESS_ALL = LC_BASE + '/api/progress/all/' + +def _break_code_lines(s): + return s.replace('\r\n', '\n').replace('\xa0', ' ').split('\n') + +def _break_paragraph_lines(s): + lines = _break_code_lines(s) + result = [] + # reserve one and only one empty line between two non-empty lines + for line in lines: + if line.strip() != '': # a line with only whitespaces is also empty + result.append(line) + result.append('') + return result + + +def _remove_description(code): + eod = code.find('[End of Description]') + if eod == -1: + return code + eol = code.find('\n', eod) + if eol == -1: + return '' + return code[eol+1:] + +def _split(s): + if isinstance(s, list): + lines = [] + for element in s: + lines.extend(_split(element)) + return lines + + # Replace all \r\n to \n and all \r (alone) to \n + s = s.replace('\r\n', '\n').replace('\r', '\n').replace('\0', '\n') + # str.split has an disadvantage that ''.split('\n') results in [''], but what we want + # is []. This small function returns [] if `s` is a blank string, that is, containing no + # characters other than whitespaces. + if s.strip() == '': + return [] + return s.split('\n') + +def _make_headers(): + assert is_login() + headers = {'Origin': LC_BASE, + 'Referer': LC_BASE, + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRFToken': session.cookies.get('csrftoken', '')} + return headers + +def get_progress(): + headers = _make_headers() + res = session.get(LC_PROGRESS_ALL, headers=headers) + if res.status_code != 200: + _echoerr('cannot get the progress') + return None + + data = res.json() + if 'solvedTotal' not in data: + return None + return data + +def _status_to_name(status): + if status == 10: + return 'Accepted' + if status == 11: + return 'Wrong Answer' + if status == 12: + return 'Memory Limit Exceeded' + if status == 13: + return 'Output Limit Exceeded' + if status == 14: + return 'Time Limit Exceeded' + if status == 15: + return 'Runtime Error' + if status == 16: + return 'Internal Error' + if status == 20: + return 'Compile Error' + if status == 21: + return 'Unknown Error' + return 'Unknown State' + + +def load_session_cookie(leetSession): + my_cookie = { + "version": 0, + "name": 'LEETCODE_SESSION', + "value": leetSession, + "port": None, + #"port_specified":False, + "domain": '.leetcode.com', + #"domain_specified":False, + #"domain_initial_dot":True, + "path": '/', + # "path_specified":True, + "secure": 1, + "expires": None, + "discard": True, + "comment": None, + "comment_url": None, + "rest": {}, + "rfc2109": False + } + + session_cookie = my_cookie + #session_cookie_raw = pickle.dumps(**my_cookie, protocol=0).decode('utf-8') + global session + session = requests.Session() + session.cookies.set(**session_cookie) + + progress = get_progress() + if progress is None: + keyring.delete_password('leetcode', 'SESSION_COOKIE') + return False + + return True + +def _check_result(submission_id): + + while True: + headers = _make_headers() + url = LC_CHECK.format(submission=submission_id) + res = session.get(url, headers=headers) + if res.status_code != 200: + _echoerr('cannot get the execution result') + return None + + r = res.json() + if r['state'] == 'SUCCESS': + prog_stage = 'Done ' + break + elif r['state'] == 'PENDING': + prog_stage = 'Pending ' + elif r['state'] == 'STARTED': + prog_stage = 'Running ' + + time.sleep(1) + + result = { + 'answer': r.get('code_answer', []), + 'runtime': r['status_runtime'], + 'state': _status_to_name(r['status_code']), + 'testcase': _split(r.get('input', r.get('last_testcase', ''))), + 'passed': r.get('total_correct') or 0, + 'total': r.get('total_testcases') or 0, + 'error': _split([v for k, v in r.items() if 'error' in k and v]) + } + + # the keys differs between the result of testing the code and submitting it + # for submission judge_type is 'large', and for testing judge_type does not exist + if r.get('judge_type') == 'large': + result['answer'] = _split(r.get('code_output', '')) + result['expected_answer'] = _split(r.get('expected_output', '')) + result['stdout'] = _split(r.get('std_output', '')) + result['runtime_percentile'] = r.get('runtime_percentile', '') + else: + # Test states cannot distinguish accepted answers from wrong answers. + if result['state'] == 'Accepted': + result['state'] = 'Finished' + result['stdout'] = _split(r.get('code_output', [])) + result['expected_answer'] = [] + result['runtime_percentile'] = r.get('runtime_percentile', '') + result['expected_answer'] = r.get('expected_code_answer', []) + return result + + +def submit_solution(slug, filetype, code=None): + assert is_login() + problem = get_problem(slug) + if not problem: + return None + + code = _remove_description(code) + + headers = _make_headers() + headers['Referer'] = LC_PROBLEM.format(slug=slug) + body = {'data_input': problem['testcase'], + 'lang': filetype, + 'question_id': str(problem['id']), + 'test_mode': False, + 'typed_code': code, + 'judge_type': 'large'} + url = LC_SUBMIT.format(slug=slug) + + res = session.post(url, json=body, headers=headers) + + if res.status_code != 200: + if 'too fast' in res.text: + print('you are sending the request too fast') + else: + print('cannot submit the solution for ' + slug) + return None + + result = _check_result(res.json()['submission_id']) + result['title'] = problem['title'] + return result + +def is_login(): + return session and 'LEETCODE_SESSION' in session.cookies + +def get_problem(slug): + assert is_login() + headers = _make_headers() + headers['Referer'] = LC_PROBLEM.format(slug=slug) + body = {'query': '''query getQuestionDetail($titleSlug : String!) { + question(titleSlug: $titleSlug) { + questionId + questionFrontendId + title + content + stats + difficulty + codeDefinition + sampleTestCase + enableRunCode + translatedContent + } +}''', + 'variables': {'titleSlug': slug}, + 'operationName': 'getQuestionDetail'} + res = session.post(LC_GRAPHQL, json=body, headers=headers) + if res.status_code != 200: + _echoerr('cannot get the problem: {}'.format(slug)) + return None + + q = res.json()['data']['question'] + content = q['translatedContent'] or q['content'] + if content is None: + _echoerr('cannot get the problem: {}'.format(slug)) + return None + + soup = BeautifulSoup(content, features='html.parser') + problem = {} + problem['id'] = q['questionId'] + problem['fid'] = q['questionFrontendId'] + problem['title'] = q['title'] + problem['slug'] = slug + problem['level'] = q['difficulty'] + problem['desc'] = _break_paragraph_lines(soup.get_text()) + problem['templates'] = {} + for t in json.loads(q['codeDefinition']): + problem['templates'][t['value']] = _break_code_lines(t['defaultCode']) + problem['testable'] = q['enableRunCode'] + problem['testcase'] = _split(q['sampleTestCase']) + stats = json.loads(q['stats']) + problem['total_accepted'] = stats['totalAccepted'] + problem['total_submission'] = stats['totalSubmission'] + problem['ac_rate'] = stats['acRate'] + return problem + + + +# load details from ENV +repo_name = os.getenv("REPO_NAME") +access_token = os.getenv("GITHUB_ACCESS_TOKEN") +pull_number = int(os.getenv("PR_NUMBER")) +leetcode_csrf_token = os.getenv("LEETCODE_CSRF_TOKEN") +leetcode_session_token = os.getenv("LEETCODE_SESSION_TOKEN") + +# authentication +g = Github(access_token) +repo = g.get_repo(repo_name) + +# get PR details +pull = repo.get_pull(pull_number) +all_files = pull.get_files() + +# get details of files from PR +file_url = "" +problem_name = "" +for i in all_files: + if i.filename[-3:] == ".py": + file_url = i.raw_url + problem_name = i.filename[9:].lower() + +# parse question id and problem name +question_id = int(problem_name[0:4]) +problem_name = re.sub("_", "-", problem_name[5:-3]) + +# get file code +r = requests.get(file_url) +code = r.text + +load_session_cookie(leetcode_session_token) +result = submit_solution(problem_name,'python3',code) +if result['state'] == 'Finished': + pull.create_issue_comment("All test case have been passed, can be merged") +else: + pull.create_issue_comment(result['state']) From 66aaf51a57c4b125ad8d2ed096e4e4c187930efd Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:24:14 +0530 Subject: [PATCH 073/161] Removed duplicate file --- .github/workflows/leetcodeChecker.yml | 2 +- codechecker.py | 114 -------------------------- leetcodeChecker.py | 3 - 3 files changed, 1 insertion(+), 118 deletions(-) delete mode 100644 codechecker.py diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 09e8828..26a34aa 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -16,7 +16,7 @@ jobs: python-version: 3.8 - name: execute checker script run: | - python codechecker.py + python leetcodeChecker.py with: github-token: ${{ github.token }} env: diff --git a/codechecker.py b/codechecker.py deleted file mode 100644 index 2c1c6b8..0000000 --- a/codechecker.py +++ /dev/null @@ -1,114 +0,0 @@ -import requests, os, re, json -from github import Github - -from dotenv import load_dotenv - -load_dotenv(dotenv_path='sample.env') - -def get_submissions(slug): - url = "https://leetcode-cn.com/graphql" - params = {'operationName': "Submissions", - 'variables': {"offset": 0, "limit": 20, "lastKey": '', "questionSlug": slug}, - 'query': '''query Submissions($offset: Int!, $limit: Int!, $lastKey: String, $questionSlug: String!) { - submissionList(offset: $offset, limit: $limit, lastKey: $lastKey, questionSlug: $questionSlug) { - lastKey - hasNext - submissions { - id - statusDisplay - lang - runtime - timestamp - url - isPending - __typename - } - __typename - } - }''' - } - - json_data = json.dumps(params).encode('utf8') - - headers = {'User-Agent': user_agent, 'Connection': 'keep-alive', 'Referer': 'https://leetcode-cn.com/accounts/login/', - "Content-Type": "application/json"} - resp = session.post(url, data=json_data, headers=headers, timeout=10) - content = resp.json() - for submission in content['data']['submissionList']['submissions']: - print(submission) - -# load details from ENV -repo_name = os.getenv("REPO_NAME") -access_token = os.getenv("GITHUB_ACCESS_TOKEN") -pull_number = int(os.getenv("PR_NUMBER")) -leetcode_csrf_token = os.getenv("LEETCODE_CSRF_TOKEN") -leetcode_session_token = os.getenv("LEETCODE_SESSION_TOKEN") - -# authentication -g = Github(access_token) -repo = g.get_repo(repo_name) - -# get PR details -pull = repo.get_pull(pull_number) -all_files = pull.get_files() - -# get details of files from PR -file_url = "" -problem_name = "" -for i in all_files: - if i.filename[-3:] == ".py": - file_url = i.raw_url - problem_name = i.filename[9:].lower() - -# parse question id and problem name -question_id = int(problem_name[0:4]) -problem_name = re.sub("_", "-", problem_name[5:-3]) - -# get file code -r = requests.get(file_url) -code = r.text - -# craft request -leetcode_submission_url = f"https://leetcode.com/problems/{problem_name}/submit/" -language = "python3" -headers = { - "Origin": "https://leetcode.com", - "content-type": "application/json", - "Referer": "https://leetcode.com/problems/two-sum/submissions/", - "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0", - # "Cookie": f"csrftoken={leetcode_csrf_token};LEETCODE_SESSION={leetcode_session_token}", -} - -headers = { - 'Connection': 'keep-alive', - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36', - 'Referer': 'https://leetcode.com/accounts/login/', - "origin": "https://leetcode.com" -} - -cookies = { - "csrftoken": leetcode_csrf_token, - "LEETCODE_SESSION": leetcode_session_token, -} -body = {"question_id": str(question_id), "lang": language, "typed_code": code} - -leetcode_submission_url2 = f"https://leetcode.com/api/problems/all" -leetcode_submission_url3 = f"https://leetcode.com/accounts/login/" -# send request -sub = requests.get(leetcode_submission_url2, headers=headers, data=body, cookies=cookies) -submit = requests.post( - leetcode_submission_url3, headers=headers, cookies=cookies -) - -print(submit.status_code) - -# get from submit url response -submission_id = "" - -# check submission against submission_id -leetcode_checker_url = f"https://leetcode.com/submissions/detail/{submission_id}/check/" - - -# sample request body extracted from network tab: {"question_id":"231","lang":"python3","typed_code":"class Solution:\n def isPowerOfTwo(self, x: int) -> bool:\n return (x != 0) and ((x & (x - 1)) == 0); \n"} -# get status of submission \ No newline at end of file diff --git a/leetcodeChecker.py b/leetcodeChecker.py index 873d7ac..ab3bb54 100644 --- a/leetcodeChecker.py +++ b/leetcodeChecker.py @@ -1,7 +1,4 @@ import requests, os, re, json, time -from github import Github -import browser_cookie3 -import keyring, pickle from bs4 import BeautifulSoup from dotenv import load_dotenv From afb25169f0e373dc330283e49afb37a4f4d1ea4a Mon Sep 17 00:00:00 2001 From: Herumb Shandilya <43719685+krypticmouse@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:26:11 +0530 Subject: [PATCH 074/161] Create 0067_Add_Binary.py Added 67th LeetCode Problem --- LeetCode/0067_Add_Binary.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LeetCode/0067_Add_Binary.py diff --git a/LeetCode/0067_Add_Binary.py b/LeetCode/0067_Add_Binary.py new file mode 100644 index 0000000..7277674 --- /dev/null +++ b/LeetCode/0067_Add_Binary.py @@ -0,0 +1,12 @@ +# Problem name : Add Binary +# Problem link : https://leetcode.com/problems/add-binary/ +# Contributor : Herumb Shandilya + +class Solution: + def addBinary(self, a: str, b: str) -> str: + l_a = [int(x) for x in list(a)] + l_b = [int(x) for x in list(b)] + num_a = sum([l_a[i]*(2**(len(l_a)-i-1)) for i in range(len(l_a))]) + num_b = sum([l_b[i]*(2**(len(l_b)-i-1)) for i in range(len(l_b))]) + s = num_a + num_b + return bin(s)[2:] From 090c4b970aa455da334e962d13d6d867d8c45524 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:30:02 +0530 Subject: [PATCH 075/161] remove env --- .github/workflows/leetcodeChecker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 26a34aa..432535d 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -19,7 +19,6 @@ jobs: python leetcodeChecker.py with: github-token: ${{ github.token }} - env: PR_NUMBER: ${{ github.event.pull_request.number }} leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }} leetcode-session: ${{ secrets.LEETCODE_SESSION }} From f64b782154fef969e88a24f53cb06197bee7b8d7 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:35:40 +0530 Subject: [PATCH 076/161] Modified YML file --- .github/workflows/leetcodeChecker.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 432535d..ca21fe5 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -15,11 +15,12 @@ jobs: with: python-version: 3.8 - name: execute checker script - run: | - python leetcodeChecker.py with: github-token: ${{ github.token }} - PR_NUMBER: ${{ github.event.pull_request.number }} + pull-number: ${{ github.event.pull_request.number }} leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }} leetcode-session: ${{ secrets.LEETCODE_SESSION }} + leetcode-session: ${{ secrets.LEETCODE_SESSION }} + run: | + python leetcodeChecker.py From 6018b96fca1c69ea7db809a5ef5ec93421a422fb Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:38:39 +0530 Subject: [PATCH 077/161] still confused --- .github/workflows/leetcodeChecker.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index ca21fe5..688ef68 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -20,7 +20,5 @@ jobs: pull-number: ${{ github.event.pull_request.number }} leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }} leetcode-session: ${{ secrets.LEETCODE_SESSION }} - leetcode-session: ${{ secrets.LEETCODE_SESSION }} - run: | - python leetcodeChecker.py + run: python leetcodeChecker.py From 7173b95f7d54cd1502767c2aa61298ad623c64b2 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:47:57 +0530 Subject: [PATCH 078/161] ! --- .github/workflows/leetcodeChecker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 688ef68..d9cf8c1 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -14,7 +14,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 - - name: execute checker script + - name: run python script + uses: ./ with: github-token: ${{ github.token }} pull-number: ${{ github.event.pull_request.number }} From 5b007a2e586a343a5b98ab939b23d28e507e049d Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 17:50:11 +0530 Subject: [PATCH 079/161] Either uses or run --- .github/workflows/leetcodeChecker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index d9cf8c1..8af94aa 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -15,7 +15,6 @@ jobs: with: python-version: 3.8 - name: run python script - uses: ./ with: github-token: ${{ github.token }} pull-number: ${{ github.event.pull_request.number }} From 0fa6c2e527171f0f383d41621d68178985a68f3e Mon Sep 17 00:00:00 2001 From: Herumb Shandilya Date: Sun, 11 Oct 2020 18:00:06 +0530 Subject: [PATCH 080/161] Added 167th Problem --- LeetCode/0167_Two_Sum_II.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 LeetCode/0167_Two_Sum_II.py diff --git a/LeetCode/0167_Two_Sum_II.py b/LeetCode/0167_Two_Sum_II.py new file mode 100644 index 0000000..6d48eb1 --- /dev/null +++ b/LeetCode/0167_Two_Sum_II.py @@ -0,0 +1,15 @@ +# Problem name : Two Sum II - Input array is sorted +# Problem link : https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ +# Contributor : Herumb Shandilya + +class Solution: + def twoSum(self, numbers: List[int], target: int) -> List[int]: + for x in numbers: + if x > target: + break + else: + if target - x == x: + return (numbers.index(x)+1,numbers.index(x)+2) + else: + if target - x in numbers: + return(numbers.index(x)+1,numbers.index(target - x)+1) \ No newline at end of file From 0772d4e668b103cab71606d5d8b14536bd83071d Mon Sep 17 00:00:00 2001 From: Soroosh Date: Sun, 11 Oct 2020 14:38:37 +0200 Subject: [PATCH 081/161] 0929 Unique Email Addresses added --- LeetCode/0929_Unique_Email_Addresses.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 LeetCode/0929_Unique_Email_Addresses.py diff --git a/LeetCode/0929_Unique_Email_Addresses.py b/LeetCode/0929_Unique_Email_Addresses.py new file mode 100644 index 0000000..55b5510 --- /dev/null +++ b/LeetCode/0929_Unique_Email_Addresses.py @@ -0,0 +1,11 @@ +class Solution: + def numUniqueEmails(self, emails: List[str]) -> int: + seen_emails = set() + for item in emails: + name, domain = item.split('@') + special_index = name.find('+') + if special_index != -1: + name = name[: special_index] + seen_emails.add(name.replace('.', '') + '@' + domain) + return len(seen_emails) + \ No newline at end of file From 2faf8411075bca365392628382db198bd74682bb Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:09:30 +0530 Subject: [PATCH 082/161] Added dependencies --- .github/workflows/leetcodeChecker.yml | 19 ++++++++++++------- leetcodeChecker.py | 3 ++- requirements.txt | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 requirements.txt diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 8af94aa..7df4027 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -14,11 +14,16 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 - - name: run python script - with: - github-token: ${{ github.token }} - pull-number: ${{ github.event.pull_request.number }} - leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }} - leetcode-session: ${{ secrets.LEETCODE_SESSION }} - run: python leetcodeChecker.py + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: run python + run: | + python leetcodeChecker.py + env: + GITHUB_ACCESS_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }} + LEETCODE_SESSION_TOKEN: ${{ secrets.LEETCODE_SESSION }} diff --git a/leetcodeChecker.py b/leetcodeChecker.py index ab3bb54..f98b1b0 100644 --- a/leetcodeChecker.py +++ b/leetcodeChecker.py @@ -3,7 +3,8 @@ from dotenv import load_dotenv -load_dotenv(dotenv_path='sample.env') +load_dotenv() +#load_dotenv(dotenv_path='sample.env') LC_BASE = 'https://leetcode.com' LC_CSRF = LC_BASE + '/ensure_csrf/' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..377e066 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.24.0 +bs4==0.0.1 From bdb71b3911ed91a668a1602abd12145b23daee71 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:12:49 +0530 Subject: [PATCH 083/161] Remove yml syntax error --- .github/workflows/leetcodeChecker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 7df4027..84dcb5d 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -16,8 +16,8 @@ jobs: python-version: 3.8 - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -r requirements.txt + python -m pip install --upgrade pip + pip install -r requirements.txt - name: run python run: | python leetcodeChecker.py From a916bee9292b66c91c29cec23d42844e42b16ac3 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:21:56 +0530 Subject: [PATCH 084/161] Unable to install via requirements.txt --- .github/workflows/leetcodeChecker.yml | 3 ++- leetcodeChecker.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 84dcb5d..70bc058 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -17,7 +17,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install requests + pip install bs4 - name: run python run: | python leetcodeChecker.py diff --git a/leetcodeChecker.py b/leetcodeChecker.py index f98b1b0..476be52 100644 --- a/leetcodeChecker.py +++ b/leetcodeChecker.py @@ -303,7 +303,9 @@ def get_problem(slug): load_session_cookie(leetcode_session_token) result = submit_solution(problem_name,'python3',code) -if result['state'] == 'Finished': +if result is None: + print("Nothing to do") +elif result['state'] == 'Finished': pull.create_issue_comment("All test case have been passed, can be merged") else: pull.create_issue_comment(result['state']) From 08916c45e5d1a2d3a3c09fb3309f5659165f83b7 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:25:45 +0530 Subject: [PATCH 085/161] Added checkout --- .github/workflows/leetcodeChecker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 70bc058..92645a2 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -8,8 +8,8 @@ jobs: runs-on: ubuntu-latest steps: - # - name: checkout repo content # checkout is unecessary - # uses: actions/checkout@v2 + - name: checkout + uses: actions/checkout@v2 - name: setup python uses: actions/setup-python@v2 with: From 8c376540786fc546151e1418294c1a4006429890 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:28:53 +0530 Subject: [PATCH 086/161] Added dotenv in requirements --- .github/workflows/leetcodeChecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 92645a2..0fd6c49 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -19,6 +19,7 @@ jobs: python -m pip install --upgrade pip pip install requests pip install bs4 + pip install python-dotenv - name: run python run: | python leetcodeChecker.py From 3e9f412730903f207dadacfe0a8bf38b3f6c8efb Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:32:55 +0530 Subject: [PATCH 087/161] Added pygithub --- .github/workflows/leetcodeChecker.yml | 4 +--- requirements.txt | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 0fd6c49..4bd67d2 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -17,9 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install requests - pip install bs4 - pip install python-dotenv + pip install -r requirements.txt - name: run python run: | python leetcodeChecker.py diff --git a/requirements.txt b/requirements.txt index 377e066..77fd5f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests==2.24.0 bs4==0.0.1 +PyGithub==1.53 From 6cc7ab1d622d24eb2ba9264f446fca9f4a2a4787 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:35:25 +0530 Subject: [PATCH 088/161] Added pythondotenv --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 77fd5f4..455c38f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ requests==2.24.0 bs4==0.0.1 PyGithub==1.53 +python-dotenv==0.14.0 + From 50bf8ebc88cc1e738c90e3052b055667011c6655 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:39:18 +0530 Subject: [PATCH 089/161] Added pyGithub --- leetcodeChecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leetcodeChecker.py b/leetcodeChecker.py index 476be52..181a6e3 100644 --- a/leetcodeChecker.py +++ b/leetcodeChecker.py @@ -1,6 +1,6 @@ import requests, os, re, json, time from bs4 import BeautifulSoup - +from github import Github from dotenv import load_dotenv load_dotenv() From 6f1405a9a2295103d099021c46592a5344aa5776 Mon Sep 17 00:00:00 2001 From: yoyogesh01 Date: Sun, 11 Oct 2020 18:45:33 +0530 Subject: [PATCH 090/161] Git repo name --- .github/workflows/leetcodeChecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index 4bd67d2..d1f7d96 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -23,6 +23,7 @@ jobs: python leetcodeChecker.py env: GITHUB_ACCESS_TOKEN: ${{ github.token }} + REPO_NAME: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }} LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }} LEETCODE_SESSION_TOKEN: ${{ secrets.LEETCODE_SESSION }} From a910002df1946b999e6870ab402103306293c4ff Mon Sep 17 00:00:00 2001 From: Deepti Date: Sun, 11 Oct 2020 19:43:08 +0530 Subject: [PATCH 091/161] add solution for LC 0216 --- LeetCode/0216_Combination_Sum_III.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/0216_Combination_Sum_III.py diff --git a/LeetCode/0216_Combination_Sum_III.py b/LeetCode/0216_Combination_Sum_III.py new file mode 100644 index 0000000..f555b1b --- /dev/null +++ b/LeetCode/0216_Combination_Sum_III.py @@ -0,0 +1,13 @@ +class Solution(object): + def combinationSum3(self, k, n): + ret = [] + self.dfs(list(range(1, 10)), k, n, [], ret) + return ret + + def dfs(self, nums, k, n, path, ret): + if k < 0 or n < 0: + return + if k == 0 and n == 0: + ret.append(path) + for i in range(len(nums)): + self.dfs(nums[i+1:], k-1, n-nums[i], path+[nums[i]], ret) \ No newline at end of file From 9890dfbe348479c7d71f0325d012a4caa89ec1b4 Mon Sep 17 00:00:00 2001 From: Deepti Date: Sun, 11 Oct 2020 19:53:41 +0530 Subject: [PATCH 092/161] add newline at the end --- LeetCode/0216_Combination_Sum_III.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LeetCode/0216_Combination_Sum_III.py b/LeetCode/0216_Combination_Sum_III.py index f555b1b..8aedcb0 100644 --- a/LeetCode/0216_Combination_Sum_III.py +++ b/LeetCode/0216_Combination_Sum_III.py @@ -10,4 +10,5 @@ def dfs(self, nums, k, n, path, ret): if k == 0 and n == 0: ret.append(path) for i in range(len(nums)): - self.dfs(nums[i+1:], k-1, n-nums[i], path+[nums[i]], ret) \ No newline at end of file + self.dfs(nums[i+1:], k-1, n-nums[i], path+[nums[i]], ret) + \ No newline at end of file From 8028a83fb2f4a75e56b8c1e6deb0dfc2b65f5cac Mon Sep 17 00:00:00 2001 From: Deepti Date: Sun, 11 Oct 2020 19:56:05 +0530 Subject: [PATCH 093/161] remove new line --- LeetCode/0216_Combination_Sum_III.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LeetCode/0216_Combination_Sum_III.py b/LeetCode/0216_Combination_Sum_III.py index 8aedcb0..f555b1b 100644 --- a/LeetCode/0216_Combination_Sum_III.py +++ b/LeetCode/0216_Combination_Sum_III.py @@ -10,5 +10,4 @@ def dfs(self, nums, k, n, path, ret): if k == 0 and n == 0: ret.append(path) for i in range(len(nums)): - self.dfs(nums[i+1:], k-1, n-nums[i], path+[nums[i]], ret) - \ No newline at end of file + self.dfs(nums[i+1:], k-1, n-nums[i], path+[nums[i]], ret) \ No newline at end of file From 7ddf2d13fa3ce428b2cd61ba5d35d2d261641155 Mon Sep 17 00:00:00 2001 From: Deepak2417 <71579689+Deepak2417@users.noreply.github.com> Date: Sun, 11 Oct 2020 20:10:07 +0530 Subject: [PATCH 094/161] Added solution for issue #383 (LeetCode id: 0123) I have added 0123_Best_Time_To_Buy_And_Sell_Stock_III.py file that will solve the problem stated. And this code has passed all the different test cases on LeetCode. --- ...123_Best_Time_To_Buy_And_Sell_Stock_III.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 LeetCode/0123_Best_Time_To_Buy_And_Sell_Stock_III.py diff --git a/LeetCode/0123_Best_Time_To_Buy_And_Sell_Stock_III.py b/LeetCode/0123_Best_Time_To_Buy_And_Sell_Stock_III.py new file mode 100644 index 0000000..96e2220 --- /dev/null +++ b/LeetCode/0123_Best_Time_To_Buy_And_Sell_Stock_III.py @@ -0,0 +1,49 @@ + +''' + Python program to solve issue: 0123- Best Time to Buy adn Sell Stock + + Issue Id: #383 +''' + + +class Solution: + + #Evalutes the all days to buy and sell stock & Generate maximum profit + def maxProfit(self, prices: List[int]) -> int: + + #Checks whether price array is empty or less then 2 elements + if prices==None or len(prices) < 2: + return 0 + + maxProfit=0 #Stores maximum profit + + minPrice=prices[0] #the minimum price from the first day to day k-1 + + #the maximum profit with at most one transaction from the first day to day k + first=[0 for x in range(0,len(prices))] + + #Evaluates maximum profit from first day to last day + for i in range(1,len(prices)): + maxProfit= max(maxProfit, prices[i]- minPrice) + first[i]= maxProfit + minPrice= min(minPrice, prices[i]) + + maxProfit=0 + maxPrice=prices[len(prices)-1] #the maximum price from day k+1 to the last day + + #the maximum profit with at most one transaction from day k to the last day + second=[0 for x in range(len(prices))] + + #Evaluates maximum profit from last day to first day + for j in range(len(prices)-2,-1,-1): + maxProfit = max(maxProfit, (maxPrice - prices[j])) + second[j] = int(maxProfit) + maxPrice = max(maxPrice, prices[j]) + + maxProfit=0 + + #Evaluates maximum profit for all days with at most TWO transaction + for k in range(0,len(prices)): + maxProfit= max(maxProfit, first[k]+second[k]) + + return maxProfit \ No newline at end of file From ce0ad409db3d08b7ff915c6d8a9273f580115db4 Mon Sep 17 00:00:00 2001 From: Rahul Date: Sun, 11 Oct 2020 20:39:56 +0530 Subject: [PATCH 095/161] Create 1598_Crawler_Log_Folder.py Added solution for Crawler Log Folder --- LeetCode/1598_Crawler_Log_Folder.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/1598_Crawler_Log_Folder.py diff --git a/LeetCode/1598_Crawler_Log_Folder.py b/LeetCode/1598_Crawler_Log_Folder.py new file mode 100644 index 0000000..411aab2 --- /dev/null +++ b/LeetCode/1598_Crawler_Log_Folder.py @@ -0,0 +1,13 @@ +class Solution: + def minOperations(self, logs: List[str]) -> int: + cnt = 0 + for log in logs: + if log == "../": + if cnt != 0: + cnt -= 1 + continue + elif log == "./": + continue + else: + cnt += 1 + return cnt if cnt > 0 else 0 From 988253113e1e3755e432ed4d5272a8cab8384c10 Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Sun, 11 Oct 2020 23:12:56 +0200 Subject: [PATCH 096/161] add find 132 pattern --- LeetCode/0456_Find_132_Pattern.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 LeetCode/0456_Find_132_Pattern.py diff --git a/LeetCode/0456_Find_132_Pattern.py b/LeetCode/0456_Find_132_Pattern.py new file mode 100644 index 0000000..da095cc --- /dev/null +++ b/LeetCode/0456_Find_132_Pattern.py @@ -0,0 +1,17 @@ +import math +import sys + +class Solution: + def Find132Pattern(self, nums: List[int]): + n = len(nums) + top = n + third = -sys.maxsize + + for i in range(n-1, -1 , -1): + if nums[i] < third: + return True + while top < n and nums[i] > nums[top]: + third = nums[top] + top = top - 1 + nums[top] = nums[i] + return False From b1711aac01bf7eed5a2521cf92410a7bbdc9aa65 Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Sun, 11 Oct 2020 23:49:39 +0200 Subject: [PATCH 097/161] update function name --- LeetCode/0456_Find_132_Pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LeetCode/0456_Find_132_Pattern.py b/LeetCode/0456_Find_132_Pattern.py index da095cc..4f74bd8 100644 --- a/LeetCode/0456_Find_132_Pattern.py +++ b/LeetCode/0456_Find_132_Pattern.py @@ -2,7 +2,7 @@ import sys class Solution: - def Find132Pattern(self, nums: List[int]): + def find132pattern(self, nums: List[int]): n = len(nums) top = n third = -sys.maxsize @@ -14,4 +14,4 @@ def Find132Pattern(self, nums: List[int]): third = nums[top] top = top - 1 nums[top] = nums[i] - return False + return False \ No newline at end of file From d3f6a98434d48adf10324007df5a1c7d3cb52933 Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Sun, 11 Oct 2020 23:55:18 +0200 Subject: [PATCH 098/161] different approach --- LeetCode/0456_Find_132_Pattern.py | 56 ++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/LeetCode/0456_Find_132_Pattern.py b/LeetCode/0456_Find_132_Pattern.py index 4f74bd8..c176439 100644 --- a/LeetCode/0456_Find_132_Pattern.py +++ b/LeetCode/0456_Find_132_Pattern.py @@ -1,17 +1,47 @@ -import math -import sys - -class Solution: +class Solution(object): def find132pattern(self, nums: List[int]): - n = len(nums) - top = n - third = -sys.maxsize + if not nums or len(nums)< 2: + return False + + m=0 + ln=len(nums) + for i in range(len(nums)-1, -1, -1): + n=nums[i] + if i+1nums[i+1]: + break + else: + m+=1 + else: + return False + + ln-=m + assert(ln and m) + mi=ln + s3mx=nums[ln-1] + ln-=1 - for i in range(n-1, -1 , -1): - if nums[i] < third: + s2mx=nums[mi] + while mi nums[top]: - third = nums[top] - top = top - 1 - nums[top] = nums[i] + elif n==s3mx and mx2>s2mx: + s2mx=mx2 + elif n>s3mx: + s2mx=s3mx + s3mx=n + while mimx2 and n Date: Sun, 11 Oct 2020 16:56:29 -0500 Subject: [PATCH 099/161] 0105 --- ...ree_from_Preorder_and_Inorder_Traversal.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LeetCode/0105_Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.py diff --git a/LeetCode/0105_Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.py b/LeetCode/0105_Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.py new file mode 100644 index 0000000..51ef9c0 --- /dev/null +++ b/LeetCode/0105_Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.py @@ -0,0 +1,19 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode: + if len(preorder) == 0: + return None + + n = preorder.pop(0) + i = inorder.index(n) + + l = self.buildTree(preorder[:i], inorder[:i]) + r = self.buildTree(preorder[i:], inorder[i+1:]) + + return TreeNode(n, l, r) + From 75e83e6e1a6a851ecdf0c947c530e2d1ed8c15f9 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Sun, 11 Oct 2020 17:13:01 -0500 Subject: [PATCH 100/161] 0101 --- LeetCode/0101_Symmetric_Tree.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LeetCode/0101_Symmetric_Tree.py diff --git a/LeetCode/0101_Symmetric_Tree.py b/LeetCode/0101_Symmetric_Tree.py new file mode 100644 index 0000000..6ee51ea --- /dev/null +++ b/LeetCode/0101_Symmetric_Tree.py @@ -0,0 +1,19 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isSymmetric(self, root: TreeNode) -> bool: + if root == None: + return True + + return self.isMirror(root.left, root.right) + + + def isMirror(self, a: TreeNode, b: TreeNode) -> bool: + if (a and b) and (a.val == b.val): + return self.isMirror(a.left, b.right) and self.isMirror(a.right, b.left) + + return a == None and b == None From f1cd4407ab608fb575ab9e2b4418c05000b1f456 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Sun, 11 Oct 2020 17:30:30 -0500 Subject: [PATCH 101/161] 0107 --- ...07_Binary_Tree_Level_Order_Traversal_II.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 LeetCode/0107_Binary_Tree_Level_Order_Traversal_II.py diff --git a/LeetCode/0107_Binary_Tree_Level_Order_Traversal_II.py b/LeetCode/0107_Binary_Tree_Level_Order_Traversal_II.py new file mode 100644 index 0000000..0d2e142 --- /dev/null +++ b/LeetCode/0107_Binary_Tree_Level_Order_Traversal_II.py @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def levelOrderBottom(self, root: TreeNode) -> List[List[int]]: + q = [] + t = [] + + if root: + q.append((0, root)) + + while len(q) > 0: + level, curr = q.pop(0) + + if level >= len(t): + t.append([]) + t[level].append(curr.val) + + if curr.left: + q.append((level + 1, curr.left)) + if curr.right: + q.append((level + 1, curr.right)) + + return reversed(t) From 43b6c6968fbe5fdcdd28ca8f83bd198076abbd8c Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Sun, 11 Oct 2020 17:37:25 -0500 Subject: [PATCH 102/161] 0103 --- ...inary_Tree_Zigzag_Level_Order_Traversal.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 LeetCode/0103_Binary_Tree_Zigzag_Level_Order_Traversal.py diff --git a/LeetCode/0103_Binary_Tree_Zigzag_Level_Order_Traversal.py b/LeetCode/0103_Binary_Tree_Zigzag_Level_Order_Traversal.py new file mode 100644 index 0000000..09d4ed5 --- /dev/null +++ b/LeetCode/0103_Binary_Tree_Zigzag_Level_Order_Traversal.py @@ -0,0 +1,31 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]: + q = [] + t = [] + + if root: + q.append((0, root)) + + while len(q) > 0: + level, curr = q.pop(0) + + if level >= len(t): + t.append([]) + t[level].append(curr.val) + + if curr.left: + q.append((level + 1, curr.left)) + if curr.right: + q.append((level + 1, curr.right)) + + for i in range(len(t)): + if i % 2 == 1: + t[i] = reversed(t[i]) + return t + From fee224157f4ee3c0e702fc23403ddb9a8b510c76 Mon Sep 17 00:00:00 2001 From: Satyam Yadav <72488628+SatyamYadav-cmd@users.noreply.github.com> Date: Mon, 12 Oct 2020 10:52:11 +0530 Subject: [PATCH 103/161] Create 0137_Single_Number_II.py --- LeetCode/0137_Single_Number_II.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 LeetCode/0137_Single_Number_II.py diff --git a/LeetCode/0137_Single_Number_II.py b/LeetCode/0137_Single_Number_II.py new file mode 100644 index 0000000..7792dcf --- /dev/null +++ b/LeetCode/0137_Single_Number_II.py @@ -0,0 +1,6 @@ +class Solution: + def singleNumber(self, nums: List[int]) -> int: + used=[] + for x in nums: + if nums.count(x)==1: + return x From 857eacfe8a7e81ae0ca318f5eb09c3e844411be5 Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Mon, 12 Oct 2020 11:03:38 +0530 Subject: [PATCH 104/161] Added Binary Tree Preorder and Postorder Traversal Code --- .../0144_Binary_Tree_Preorder_Traversal.py | 16 ++++++++++ .../0145_Binary_Tree_Postorder_Traversal.py | 31 +++++++++++++++++++ PULL_REQUEST_TEMPLATE.md | 12 +++---- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 LeetCode/0144_Binary_Tree_Preorder_Traversal.py create mode 100644 LeetCode/0145_Binary_Tree_Postorder_Traversal.py diff --git a/LeetCode/0144_Binary_Tree_Preorder_Traversal.py b/LeetCode/0144_Binary_Tree_Preorder_Traversal.py new file mode 100644 index 0000000..05b735d --- /dev/null +++ b/LeetCode/0144_Binary_Tree_Preorder_Traversal.py @@ -0,0 +1,16 @@ +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right +class Solution: + def preorderTraversal(self, root: TreeNode) -> List[int]: + self.ans=[] + def preorder(root): + if root is None: + return + self.ans.append(root.val) + preorder(root.left) + preorder(root.right) + preorder(root) + return self.ans \ No newline at end of file diff --git a/LeetCode/0145_Binary_Tree_Postorder_Traversal.py b/LeetCode/0145_Binary_Tree_Postorder_Traversal.py new file mode 100644 index 0000000..9442cde --- /dev/null +++ b/LeetCode/0145_Binary_Tree_Postorder_Traversal.py @@ -0,0 +1,31 @@ +class TreeNode(object): + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right +class Solution(object): + def postorderTraversal(self, root: TreeNode) -> List[int]: + postorder = [] + s = [] + v = set() + if root: + s.append(root) + while s: + r = s[-1] + if r not in v: + if r.right: + s.append(r.right) + v.add(r) + + if r.left: + s.append(r.left) + v.add(r) + + if r.right is None and r.left is None: + r = s.pop() + postorder.append(r.val) + else: + r = s.pop() + postorder.append(r.val) + + return postorder \ No newline at end of file diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index d64c54e..d0a0599 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -2,12 +2,12 @@ ### All Submissions: -* [ ] I have read the CONTRIBUTING document. -* [ ] My code is written in **Python3** and is ending with _.py_ -* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? -* [ ] I have checked that my submission does pass the test on LeetCode.com -* [ ] Does your filename follow the naming Conventions? -* [ ] Have you linked your PR to an Issue? +- [x] I have read the CONTRIBUTING document. +- [x] My code is written in **Python3** and is ending with _.py_ +- [x] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? +- [x] I have checked that my submission does pass the test on LeetCode.com +- [x] Does your filename follow the naming Conventions? +- [x] Have you linked your PR to an Issue? **Closing issues** From 249be6e43ef02df52e2f36599b7cff2c3c9f049a Mon Sep 17 00:00:00 2001 From: Cheryl An-Yiing Kong <“27339352+cakon2@users.noreply.github.com”> Date: Mon, 12 Oct 2020 14:33:59 +0900 Subject: [PATCH 105/161] Add solution file for 1351 --- .../1351_Count_Negative_Numbers_in_Sorted_Matrix.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 LeetCode/1351_Count_Negative_Numbers_in_Sorted_Matrix.py diff --git a/LeetCode/1351_Count_Negative_Numbers_in_Sorted_Matrix.py b/LeetCode/1351_Count_Negative_Numbers_in_Sorted_Matrix.py new file mode 100644 index 0000000..54b9947 --- /dev/null +++ b/LeetCode/1351_Count_Negative_Numbers_in_Sorted_Matrix.py @@ -0,0 +1,11 @@ +class Solution: + def countNegatives(self, grid: List[List[int]]) -> int: + count = 0 + for row in grid: + for index in range(len(row)-1, -1, -1): + if row[index] < 0: + count += 1 + else: + break + + return count \ No newline at end of file From 4017517cde5a7e8a6dae53e0706de59d40b5f0a5 Mon Sep 17 00:00:00 2001 From: Suhrid Mathur Date: Mon, 12 Oct 2020 11:59:29 +0530 Subject: [PATCH 106/161] Solution added for #1470 Shuffle The Array --- LeetCode/1470_Shuffle_The_Array | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/1470_Shuffle_The_Array diff --git a/LeetCode/1470_Shuffle_The_Array b/LeetCode/1470_Shuffle_The_Array new file mode 100644 index 0000000..0892eb7 --- /dev/null +++ b/LeetCode/1470_Shuffle_The_Array @@ -0,0 +1,13 @@ +class Solution: + def shuffle(self, nums: List[int], n: int) -> List[int]: + shuffled_list = [0]*(2*n) + left_index = 0 + right_index = n + for index in range(0, 2*n): + if index%2 == 0: + shuffled_list[index] = nums[left_index] + left_index += 1 + else: + shuffled_list[index] = nums[right_index] + right_index += 1 + return shuffled_list From cfe739f04069b5c81a86ea365ca9abad419eab6d Mon Sep 17 00:00:00 2001 From: Abhishek Tiwari <63968306+AbhishekTiwari07@users.noreply.github.com> Date: Mon, 12 Oct 2020 12:31:25 +0530 Subject: [PATCH 107/161] Create 0119_Pascal_Triangle2.py --- LeetCode/0119_Pascal_Triangle2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LeetCode/0119_Pascal_Triangle2.py diff --git a/LeetCode/0119_Pascal_Triangle2.py b/LeetCode/0119_Pascal_Triangle2.py new file mode 100644 index 0000000..02171f9 --- /dev/null +++ b/LeetCode/0119_Pascal_Triangle2.py @@ -0,0 +1,20 @@ +class Solution(object): + def getRow(self, rowIndex): + """ + :type rowIndex: int + :rtype: List[int] + """ + + if rowIndex == 0: + return [1] + if rowIndex == 1: + return [1,1] + + init = [1,1] + for i in range(0, rowIndex-1): + new_vec = [] + for v in range(0, len(init)-1): + new_vec.append(init[v] + init[v+1]) + new_vec = [1] + new_vec + [1] + init = new_vec + return init From 9789939b586bcad58e7f492f8467e5f88ad1b967 Mon Sep 17 00:00:00 2001 From: javmarina Date: Mon, 12 Oct 2020 11:46:40 +0200 Subject: [PATCH 108/161] Added solution for problem 203 --- LeetCode/0203_Remove_Linked_List_Elements.py | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 LeetCode/0203_Remove_Linked_List_Elements.py diff --git a/LeetCode/0203_Remove_Linked_List_Elements.py b/LeetCode/0203_Remove_Linked_List_Elements.py new file mode 100644 index 0000000..9f8febb --- /dev/null +++ b/LeetCode/0203_Remove_Linked_List_Elements.py @@ -0,0 +1,25 @@ +# 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 removeElements(self, head, val): + """ + :type head: ListNode + :type val: int + :rtype: ListNode + """ + while head: + if head.val == val: + head = head.next + else: + break + currentNode = head + while currentNode: + while currentNode.next and currentNode.next.val == val: + currentNode.next = currentNode.next.next + + currentNode = currentNode.next + return head From 8eb8fa7967e9ff285d9dd61f5c72069675350161 Mon Sep 17 00:00:00 2001 From: javmarina Date: Mon, 12 Oct 2020 12:17:59 +0200 Subject: [PATCH 109/161] Added solution for 1518 --- LeetCode/1518_Water_Bottles.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 LeetCode/1518_Water_Bottles.py diff --git a/LeetCode/1518_Water_Bottles.py b/LeetCode/1518_Water_Bottles.py new file mode 100644 index 0000000..d6544e5 --- /dev/null +++ b/LeetCode/1518_Water_Bottles.py @@ -0,0 +1,26 @@ +class Solution(object): + def numWaterBottles(self, numBottles, numExchange): + """ + :type numBottles: int + :type numExchange: int + :rtype: int + """ + full = numBottles + empty = 0 + drank = 0 + + while True: + # 1. Drink + empty += full + drank += full + full = 0 + + # 2. Exchange + while empty >= numExchange: + empty -= numExchange + full += 1 + + if not full: + break + + return drank From 1b5b373652c8a18a3f8a8ed0b3c0b9917326b83f Mon Sep 17 00:00:00 2001 From: polo-sec Date: Mon, 12 Oct 2020 11:34:24 +0000 Subject: [PATCH 110/161] Implemented challenge number 0617, Merge Two Binary Trees --- LeetCode/0617_Merge_Two_Binary_Trees.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LeetCode/0617_Merge_Two_Binary_Trees.py diff --git a/LeetCode/0617_Merge_Two_Binary_Trees.py b/LeetCode/0617_Merge_Two_Binary_Trees.py new file mode 100644 index 0000000..feb8819 --- /dev/null +++ b/LeetCode/0617_Merge_Two_Binary_Trees.py @@ -0,0 +1,20 @@ +#Definition for a binary tree node. +#class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None +class Solution: + def mergeTrees(self, t1, t2): + """ + :type t1: TreeNode + :type t2: TreeNode + :rtype: TreeNode + """ + if t1 is None: + return t2 + if t2 is not None: + t1.val += t2.val + t1.left = self.mergeTrees(t1.left, t2.left) + t1.right = self.mergeTrees(t1.right, t2.right) + return t1 From d10ecdd1ff8280bfdb41a1f735c29c5433ba0872 Mon Sep 17 00:00:00 2001 From: aman1833 <33142696+aman1833@users.noreply.github.com> Date: Mon, 12 Oct 2020 20:07:32 +0530 Subject: [PATCH 111/161] Create 997_Find_The_Town_Judge.py --- LeetCode/997_Find_The_Town_Judge.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LeetCode/997_Find_The_Town_Judge.py diff --git a/LeetCode/997_Find_The_Town_Judge.py b/LeetCode/997_Find_The_Town_Judge.py new file mode 100644 index 0000000..63b8db5 --- /dev/null +++ b/LeetCode/997_Find_The_Town_Judge.py @@ -0,0 +1,19 @@ +def findJudge(self, N: int, trust: List[List[int]]) -> int: + if N==1: + return 1 + d1={} + d2={} + for i, j in trust: + if j in d1: + d1[j]+=1 + else: + d1[j]=1 + if i in d2: + d2[i]+=1 + else: + d2[i]=1 + for i,j in d1.items(): + if j==N-1: + if i not in d2: + return i + return -1 From b9c58b1f081b29bf0113cdc94b927a0ed456a867 Mon Sep 17 00:00:00 2001 From: aman1833 <33142696+aman1833@users.noreply.github.com> Date: Mon, 12 Oct 2020 20:46:12 +0530 Subject: [PATCH 112/161] Delete fast_fibonacci.py --- fast_fibonacci.py | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 fast_fibonacci.py diff --git a/fast_fibonacci.py b/fast_fibonacci.py deleted file mode 100644 index e7bdfac..0000000 --- a/fast_fibonacci.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import annotations - -import sys - - -def fibonacci(n: int) -> int: - """ - return F(n) - >>> [fibonacci(i) for i in range(13)] - [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144] - """ - if n < 0: - raise ValueError("Negative arguments are not supported") - return _fib(n)[0] - - -# returns (F(n), F(n-1)) -def _fib(n: int) -> tuple[int, int]: - if n == 0: # (F(0), F(1)) - return (0, 1) - - # F(2n) = F(n)[2F(n+1) − F(n)] - # F(2n+1) = F(n+1)^2+F(n)^2 - a, b = _fib(n // 2) - c = a * (b * 2 - a) - d = a * a + b * b - return (d, c + d) if n % 2 else (c, d) - - -if __name__ == "__main__": - n = int(sys.argv[1]) - print(f"fibonacci({n}) is {fibonacci(n)}") From 3cb5c29f3043db472ac037f519a2b930380268fc Mon Sep 17 00:00:00 2001 From: aman1833 <33142696+aman1833@users.noreply.github.com> Date: Mon, 12 Oct 2020 20:49:48 +0530 Subject: [PATCH 113/161] Update 997_Find_The_Town_Judge.py --- LeetCode/997_Find_The_Town_Judge.py | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/LeetCode/997_Find_The_Town_Judge.py b/LeetCode/997_Find_The_Town_Judge.py index 63b8db5..37e928f 100644 --- a/LeetCode/997_Find_The_Town_Judge.py +++ b/LeetCode/997_Find_The_Town_Judge.py @@ -1,19 +1,21 @@ -def findJudge(self, N: int, trust: List[List[int]]) -> int: - if N==1: - return 1 - d1={} - d2={} - for i, j in trust: - if j in d1: - d1[j]+=1 - else: - d1[j]=1 - if i in d2: - d2[i]+=1 - else: - d2[i]=1 - for i,j in d1.items(): - if j==N-1: - if i not in d2: - return i +class Solution: + def findJudge(self, N: int, trust: List[List[int]]) -> int: + m=len(trust) + if 1==N: + if 0==m: + return 1 + tmp={} + dic={} + for i in range(m): + tmp[trust[i][0]]=1 + for i in range(m): + if trust[i][1] not in tmp: + if trust[i][1] not in dic: + dic[trust[i][1]]=1 + else: + dic[trust[i][1]]+=1 + for key in dic: + if N-1==dic[key]: + return key return -1 + From a7e1bc083a068f7e304426fb3ea4825ebecb4ea6 Mon Sep 17 00:00:00 2001 From: Ahkam Naseek Date: Mon, 12 Oct 2020 21:03:40 +0530 Subject: [PATCH 114/161] Fixed issue #756 Count Complete tree nodes --- LeetCode/0222_Count_Complete_Tree_Nodes.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 LeetCode/0222_Count_Complete_Tree_Nodes.py diff --git a/LeetCode/0222_Count_Complete_Tree_Nodes.py b/LeetCode/0222_Count_Complete_Tree_Nodes.py new file mode 100644 index 0000000..eb633a0 --- /dev/null +++ b/LeetCode/0222_Count_Complete_Tree_Nodes.py @@ -0,0 +1,25 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def countNodes(self, root: TreeNode) -> int: + + if root == None: return 0 + right, left = root, root + h_l , h_r = 0, 0 + + while left != None: + h_l +=1 + left = left.left + + while right != None: + h_r +=1 + right = right.right + + + if (h_l == h_r) : return(1 << h_l) -1 + + return 1+ self.countNodes(root.left) + self.countNodes(root.right) From 1557ee6b786d07e5a937c1faf7f7d35634d0c60e Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Tue, 13 Oct 2020 01:00:26 +0530 Subject: [PATCH 115/161] Made necessary changes --- .../0145_Binary_Tree_Postorder_Traversal.py | 31 ------------------- PULL_REQUEST_TEMPLATE.md | 12 +++---- 2 files changed, 6 insertions(+), 37 deletions(-) delete mode 100644 LeetCode/0145_Binary_Tree_Postorder_Traversal.py diff --git a/LeetCode/0145_Binary_Tree_Postorder_Traversal.py b/LeetCode/0145_Binary_Tree_Postorder_Traversal.py deleted file mode 100644 index 9442cde..0000000 --- a/LeetCode/0145_Binary_Tree_Postorder_Traversal.py +++ /dev/null @@ -1,31 +0,0 @@ -class TreeNode(object): - def __init__(self, val=0, left=None, right=None): - self.val = val - self.left = left - self.right = right -class Solution(object): - def postorderTraversal(self, root: TreeNode) -> List[int]: - postorder = [] - s = [] - v = set() - if root: - s.append(root) - while s: - r = s[-1] - if r not in v: - if r.right: - s.append(r.right) - v.add(r) - - if r.left: - s.append(r.left) - v.add(r) - - if r.right is None and r.left is None: - r = s.pop() - postorder.append(r.val) - else: - r = s.pop() - postorder.append(r.val) - - return postorder \ No newline at end of file diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index d0a0599..74ca7c3 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -2,12 +2,12 @@ ### All Submissions: -- [x] I have read the CONTRIBUTING document. -- [x] My code is written in **Python3** and is ending with _.py_ -- [x] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? -- [x] I have checked that my submission does pass the test on LeetCode.com -- [x] Does your filename follow the naming Conventions? -- [x] Have you linked your PR to an Issue? +- [ ] I have read the CONTRIBUTING document. +- [ ] My code is written in **Python3** and is ending with _.py_ +- [ ] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? +- [ ] I have checked that my submission does pass the test on LeetCode.com +- [ ] Does your filename follow the naming Conventions? +- [ ] Have you linked your PR to an Issue? **Closing issues** From cc865e3c00e3193269959cb877bc93613db03bd8 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <61814592+RgnDunes@users.noreply.github.com> Date: Tue, 13 Oct 2020 03:03:39 +0530 Subject: [PATCH 116/161] Copied and pasted original contents in PULL_REQUEST_TEMPLATE.md --- PULL_REQUEST_TEMPLATE.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 74ca7c3..d64c54e 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -2,12 +2,12 @@ ### All Submissions: -- [ ] I have read the CONTRIBUTING document. -- [ ] My code is written in **Python3** and is ending with _.py_ -- [ ] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? -- [ ] I have checked that my submission does pass the test on LeetCode.com -- [ ] Does your filename follow the naming Conventions? -- [ ] Have you linked your PR to an Issue? +* [ ] I have read the CONTRIBUTING document. +* [ ] My code is written in **Python3** and is ending with _.py_ +* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? +* [ ] I have checked that my submission does pass the test on LeetCode.com +* [ ] Does your filename follow the naming Conventions? +* [ ] Have you linked your PR to an Issue? **Closing issues** From 61f4604120485846939ef50efcd03d4b09e4a7c1 Mon Sep 17 00:00:00 2001 From: Cheryl An-Yiing Kong <“27339352+cakon2@users.noreply.github.com”> Date: Tue, 13 Oct 2020 09:42:06 +0900 Subject: [PATCH 117/161] Add Group_People_Given_Group_Size_They_Belong_To.py --- ...oup_People_Given_the_Group_Size_They_Belong_To.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LeetCode/1282_Group_People_Given_the_Group_Size_They_Belong_To.py diff --git a/LeetCode/1282_Group_People_Given_the_Group_Size_They_Belong_To.py b/LeetCode/1282_Group_People_Given_the_Group_Size_They_Belong_To.py new file mode 100644 index 0000000..a257644 --- /dev/null +++ b/LeetCode/1282_Group_People_Given_the_Group_Size_They_Belong_To.py @@ -0,0 +1,12 @@ +class Solution: + def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: + maxGroupSize= max(groupSizes) + groups = [[] for i in range(maxGroupSize)] + + for i, p in enumerate(groupSizes): + groups[p-1].append(i) + if len(groups[p-1]) == p: + groups.append(groups[p-1]) + groups[p-1] = [] + + return groups[maxGroupSize:] From c6c3c7c7f351a229db4835e2d140f4c5e0b6c972 Mon Sep 17 00:00:00 2001 From: Vikram Bais Date: Tue, 13 Oct 2020 15:25:04 +0530 Subject: [PATCH 118/161] added python code for Reverse Words in a String code for Reverse Words in a String --- LeetCode/0151_Reverse_Words_in_a_String.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 LeetCode/0151_Reverse_Words_in_a_String.py diff --git a/LeetCode/0151_Reverse_Words_in_a_String.py b/LeetCode/0151_Reverse_Words_in_a_String.py new file mode 100644 index 0000000..6e624f4 --- /dev/null +++ b/LeetCode/0151_Reverse_Words_in_a_String.py @@ -0,0 +1,10 @@ +class Solution: + def reverseWords(self, s): + list_of_string = s.split(' ') + #appliying filter function to remove extraspaces from list + new_list = list(filter(lambda x : True if (x!="") else False, list_of_string)) + #taking reverse of output list + new_list.reverse() + #joining the elements if list + final_string = " ".join(str(k) for k in new_list) + return final_string From c1806b462a87fd69f3721d949cd913813de5562b Mon Sep 17 00:00:00 2001 From: "Dev.ruji" <43924465+devruji@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:52:11 +0700 Subject: [PATCH 119/161] Create 1556_Thousand_Separator.py --- LeetCode/1556_Thousand_Separator.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 LeetCode/1556_Thousand_Separator.py diff --git a/LeetCode/1556_Thousand_Separator.py b/LeetCode/1556_Thousand_Separator.py new file mode 100644 index 0000000..23310d2 --- /dev/null +++ b/LeetCode/1556_Thousand_Separator.py @@ -0,0 +1,11 @@ +class Solution: + def thousandSeparator(self, n: int) -> str: + num = n + ans = f'{num:,}' + return ans + + +if __name__ == '__main__': + x = Solution() + answer = x.thousandSeparator(2**31) + print(answer) From f2a83e4363c313a314ab75d58a213e6fba7b67fd Mon Sep 17 00:00:00 2001 From: "Dev.ruji" <43924465+devruji@users.noreply.github.com> Date: Tue, 13 Oct 2020 18:08:44 +0700 Subject: [PATCH 120/161] Changed comma to dot --- LeetCode/1556_Thousand_Separator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LeetCode/1556_Thousand_Separator.py b/LeetCode/1556_Thousand_Separator.py index 23310d2..b7899e8 100644 --- a/LeetCode/1556_Thousand_Separator.py +++ b/LeetCode/1556_Thousand_Separator.py @@ -1,11 +1,11 @@ class Solution: def thousandSeparator(self, n: int) -> str: num = n - ans = f'{num:,}' + ans = f'{num:,}'.replace(',', '.') return ans if __name__ == '__main__': x = Solution() - answer = x.thousandSeparator(2**31) + answer = x.thousandSeparator(1234) print(answer) From dd84b559af11ac1924ef9d5256f63493cebd11c9 Mon Sep 17 00:00:00 2001 From: "Dev.ruji" <43924465+devruji@users.noreply.github.com> Date: Tue, 13 Oct 2020 18:09:03 +0700 Subject: [PATCH 121/161] Changed comma to dot --- LeetCode/1556_Thousand_Separator.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/LeetCode/1556_Thousand_Separator.py b/LeetCode/1556_Thousand_Separator.py index b7899e8..ef46674 100644 --- a/LeetCode/1556_Thousand_Separator.py +++ b/LeetCode/1556_Thousand_Separator.py @@ -3,9 +3,3 @@ def thousandSeparator(self, n: int) -> str: num = n ans = f'{num:,}'.replace(',', '.') return ans - - -if __name__ == '__main__': - x = Solution() - answer = x.thousandSeparator(1234) - print(answer) From ea2f83b643413c057a1283ec1c85846c8f36997c Mon Sep 17 00:00:00 2001 From: Suhrid Mathur Date: Tue, 13 Oct 2020 18:08:28 +0530 Subject: [PATCH 122/161] Rename 1470_Shuffle_The_Array to 1470_Shuffle_The_Array.py --- LeetCode/{1470_Shuffle_The_Array => 1470_Shuffle_The_Array.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LeetCode/{1470_Shuffle_The_Array => 1470_Shuffle_The_Array.py} (100%) diff --git a/LeetCode/1470_Shuffle_The_Array b/LeetCode/1470_Shuffle_The_Array.py similarity index 100% rename from LeetCode/1470_Shuffle_The_Array rename to LeetCode/1470_Shuffle_The_Array.py From fb0b02dc2c5ffbc81c5b961e25fa81074358c7b2 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Wed, 28 Oct 2020 08:57:10 +0100 Subject: [PATCH 123/161] Delete 0006_ZigZag_Conversion.py --- LeetCode/0006_ZigZag_Conversion.py | 176 ----------------------------- 1 file changed, 176 deletions(-) delete mode 100644 LeetCode/0006_ZigZag_Conversion.py diff --git a/LeetCode/0006_ZigZag_Conversion.py b/LeetCode/0006_ZigZag_Conversion.py deleted file mode 100644 index 2d7de9c..0000000 --- a/LeetCode/0006_ZigZag_Conversion.py +++ /dev/null @@ -1,176 +0,0 @@ -''' -## Description of the Problem - -The string "PAYPALISHIRING" is written in a zigzag pattern -on a given number of rows like this: - -(you may want to display this pattern in a fixed font for better legibility) - -``` -P A H N -A P L S I I G -Y I R -``` - -And then read line by line: "PAHNAPLSIIGYIR" - -Write the code that will take a string and make this conversion given a number of rows: - -``` -string convert(string s, int numRows); -``` - -## Example 1: -``` -Input: s = "PAYPALISHIRING", numRows = 3 -Output: "PAHNAPLSIIGYIR" -``` - -## Example 2: -``` -Input: s = "PAYPALISHIRING", numRows = 4 -Output: "PINALSIGYAHRPI" -``` - -## Explanation: - -``` -P I N -A L S I G -Y A H R -P I -``` - -## Example 3: - -``` -Input: s = "A", numRows = 1 -Output: "A" -``` - -## Constraints: - -- 1 <= s.length <= 1000 -- s consists of English letters (lower-case and upper-case), ',' and '.'. -- 1 <= numRows <= 1000 - - -## Link To The LeetCode Problem -[6. ZigZag Conversion](https://leetcode.com/problems/zigzag-conversion/) -''' - - -class Solution: - s = '' - numRows = 1 - - # transitionColumns is the number of extra columns needed to get the - # text from the bottom row back to the top row - def zigZagTransitionColumns(self) -> int: - transitionColumns = self.numRows - 2 - if transitionColumns < 0: - transitionColumns = 0 - return transitionColumns - - # patternColumns is the number of columns taken up by each full pattern - # the first column is downward, and then we need columns for the upward - def zigZagPatternColumns(self) -> int: - return 1 + self.zigZagTransitionColumns() - - # patternSize is the number of elements in each repeated pattern - def zigZagPatternLength(self) -> int: - # there are numRows letters in the first column - # followed by one letter per transitionColumn - return self.numRows + self.zigZagTransitionColumns() - - # computes the number of total columns needed by this string - def zigZagMatrixColumns(self) -> int: - patternLength = self.zigZagPatternLength() - fullPatternCount = len(self.s) // patternLength - columns = self.zigZagPatternColumns() * fullPatternCount - - # how many extra letters are there? - extraLetters = len(self.s) - (patternLength * fullPatternCount) - if extraLetters > 0: - columns += 1 - if extraLetters > self.numRows: - columns += extraLetters - self.numRows - return columns - - # converts the index of the input string to the address - # in the output matrix - def zigZagMatrixIndex(self, elementIndex: int) -> tuple: - patternLength = self.zigZagPatternLength() - - # which pattern repetition holds this element (zero-based) - patternOfElement = elementIndex // patternLength - - # where in the pattern repetition is this element - indexInPattern = elementIndex % patternLength - - matrixRow = indexInPattern - matrixColumn = patternOfElement * self.zigZagPatternColumns() - bottomRowIndex = self.numRows - 1 - - # correct the row and column numbers (remember these are zero-based) - if indexInPattern > bottomRowIndex: - extraColumns = indexInPattern - bottomRowIndex - matrixColumn = matrixColumn + extraColumns - - # row decrements by 1 for each extra column - matrixRow = bottomRowIndex - extraColumns - - # i, j - return (matrixColumn, matrixRow) - - # creates a zigzag matrix - def generateZigZagMatrix(self) -> list: - matrix = [] - for i in range(self.zigZagMatrixColumns()): - matrix.append([]) - for j in range(self.numRows): - matrix[i].append('') - for elementIndex, char in enumerate(self.s): - i, j = self.zigZagMatrixIndex(elementIndex) - matrix[i][j] = char - return matrix - - # prints out the zigzag matrix - def generateZigZagString(self, nullChar: str = ' ', lineEndings: str = '\n'): - lines = [] - matrix = self.generateZigZagMatrix() - for j in range(self.numRows): - rowChars = [] - for i in range(self.zigZagMatrixColumns()): - char = matrix[i][j] - rowChars.append(char if char != '' else nullChar) - lines.append(''.join(rowChars)) - return lineEndings.join(lines) - - def zigZagConversion(self, s: str, numRows: int, asMatrix: bool = False) -> str: - ''' - The ZigZag format fills all available rows vertically in the first column, - then, fills rows "diagonally" on the way back up to the top row of a subsequent - column, and then repeats. - - The input string is the normal content. - ''' - self.s = s - self.numRows = numRows - if asMatrix: - return self.generateZigZagString(nullChar=' ', lineEndings='\n') - else: - return self.generateZigZagString(nullChar='', lineEndings='') - - -# testing -if __name__ == '__main__': - toConvert = 'PAYPALISHIRING' - converter = Solution() - for i in range(4): - print(f'\nENCODING: {toConvert} with {i+1} rows') - print('\n-- matrix -----------------') - print(converter.zigZagConversion(toConvert, numRows=i+1, asMatrix=True)) - print('\n-- line -------------------') - print(converter.zigZagConversion(toConvert, numRows=i+1, asMatrix=False)) - print() From 86cedd3b8bd3c695ca19f19b5f55d3ab66056c9b Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Wed, 28 Oct 2020 09:06:23 +0100 Subject: [PATCH 124/161] Delete 0092_Decode_Ways.py --- LeetCode/0092_Decode_Ways.py | 40 ------------------------------------ 1 file changed, 40 deletions(-) delete mode 100644 LeetCode/0092_Decode_Ways.py diff --git a/LeetCode/0092_Decode_Ways.py b/LeetCode/0092_Decode_Ways.py deleted file mode 100644 index 0f0c382..0000000 --- a/LeetCode/0092_Decode_Ways.py +++ /dev/null @@ -1,40 +0,0 @@ -''' -Problem:- -A message containing letters from A-Z is being encoded to numbers using the following mapping: - -'A' -> 1 -'B' -> 2 -... -'Z' -> 26 -Given a non-empty string containing only digits, determine the total number of ways to decode it. - -The answer is guaranteed to fit in a 32-bit integer. - -Example 1: - -Input: s = "12" -Output: 2 -Explanation: It could be decoded as "AB" (1 2) or "L" (12). - -Example 2: - -Input: s = "226" -Output: 3 -Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6). -''' - -class Solution: - def numDecodings(self, s: str) -> int: - @lru_cache(None) - def dp(i): - if i == len(s): - return 1 - ans = 0 - if s[i] != '0': - ans += dp(i+1) - if s[i] == '1' and i+1< len(s): - ans += dp(i+2) - if s[i] == '2' and i+1 < len(s) and s[i+1] <= '6': - ans += dp(i+2) - return ans - return dp(0) From 3774432b7a896e099a0bc2b4ec63b8bf20e7f4b5 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Wed, 28 Oct 2020 09:46:14 +0100 Subject: [PATCH 125/161] Delete 0046_Permutations.py --- LeetCode/0046_Permutations.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 LeetCode/0046_Permutations.py diff --git a/LeetCode/0046_Permutations.py b/LeetCode/0046_Permutations.py deleted file mode 100644 index d0ba022..0000000 --- a/LeetCode/0046_Permutations.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def permutations(self, nums: List[int]): - if not nums: - yield [] - for num in nums: - remaining = list(nums) - remaining.remove(num) - for perm in self.permutations(remaining): - yield [num] + list(perm) - - def permute(self, nums: List[int]) -> List[List[int]]: - return list(self.permutations(nums)) From 68dea523387b7b3a794e5ef38af8a6548bf08cb6 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Wed, 28 Oct 2020 10:12:11 +0100 Subject: [PATCH 126/161] Delete 0067_Add_Binary.py --- LeetCode/0067_Add_Binary.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 LeetCode/0067_Add_Binary.py diff --git a/LeetCode/0067_Add_Binary.py b/LeetCode/0067_Add_Binary.py deleted file mode 100644 index 7277674..0000000 --- a/LeetCode/0067_Add_Binary.py +++ /dev/null @@ -1,12 +0,0 @@ -# Problem name : Add Binary -# Problem link : https://leetcode.com/problems/add-binary/ -# Contributor : Herumb Shandilya - -class Solution: - def addBinary(self, a: str, b: str) -> str: - l_a = [int(x) for x in list(a)] - l_b = [int(x) for x in list(b)] - num_a = sum([l_a[i]*(2**(len(l_a)-i-1)) for i in range(len(l_a))]) - num_b = sum([l_b[i]*(2**(len(l_b)-i-1)) for i in range(len(l_b))]) - s = num_a + num_b - return bin(s)[2:] From d730a5a8aceaed2f16cd377082417f1f23fc4430 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Thu, 29 Oct 2020 10:28:46 +0100 Subject: [PATCH 127/161] Create 0260_Single_Number_III.py --- LeetCode/0260_Single_Number_III.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 LeetCode/0260_Single_Number_III.py diff --git a/LeetCode/0260_Single_Number_III.py b/LeetCode/0260_Single_Number_III.py new file mode 100644 index 0000000..065d8e6 --- /dev/null +++ b/LeetCode/0260_Single_Number_III.py @@ -0,0 +1,7 @@ +class Solution: + def singleNumber(self, N: List[int]) -> int: + L, d = len(N), set() + for n in N: + if n in d: d.remove(n) + else: d.add(n) + return d \ No newline at end of file From 5ecf1259995cba9f6a33fb923197a67162d00894 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Thu, 29 Oct 2020 10:29:27 +0100 Subject: [PATCH 128/161] moved files to LeetCode Folder --- .DS_Store | Bin 8196 -> 0 bytes ...umbers_Are_Smaller_Than_the_Current_Number.py | 0 .../1588_SumOfAllOddLengthSubarrays.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store rename 1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py => LeetCode/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py (100%) rename 1588_SumOfAllOddLengthSubarrays.py => LeetCode/1588_SumOfAllOddLengthSubarrays.py (100%) diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 2b814e5fb2bf3fee468e4839f097ac358da063b3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMTWl0n7(U-pV1|h>t(A+i*)0W1u!iMg5izjrwrDTVhHYuNwVmA=Vd8XVnVH>! zO=C40jS%$38;$bdHKIO=w@$#T1@Iqot{Lh>zp*Q1`Au?xk&VSDN zFQ@-E-$lADuEhjK(n;m#o38N!tj-cS&%PJYS2 zoFOe_)J6zI2uwwQZy$-ZF@rw-jraGw<>X0sHD9z$&rhYkM{HKb>^XBKd7dIG^A-6( z?vOK>^EJQZWi+=>U79m>Bd@vLrtTl=H0&nJC>wUW+ot)3yN?@pI*vsKqOaw5o5o-3{v-hKFTIT2i-tS8wTw6DLRCc=N5d&z=i>7{WIRs}$qw?Rn}=fyDC4 zSpi9GY#fqHH$bA?7H?^7+p)8~PgP5vvCFVD-z*!Al)TrcF7PP*=7M8)xJH@M?k+f1 zX}~5;WkItFB{DX)Sys+`R9F{W$Fe#c&-6{l-qYh7M|`g1fhMSW_Ii%%XMiwP%EpHYGq+}+4Ri3WpoYlr?yA)3Wlwl z_QAdM9Bkiw*fddBpt5GRD|2Bkq# zb-ByZ@`fd*HYuAWwN>sei*&_gwX#)`dkW6L043vzxlFuKQoodX`ND0Q=eHLPo7U#3 zZLf*P_we~`x^C!_LvjS&}z&`U1XQp@9YnDg@8NxXfRAw&=kPhczy!_UbzpE=sOgy=KFv zEt%_dn8bh^nHZ2yuq$BQIIDt(K9R~|M<|IdBBya=rj4P_<(o(vk^M&Gy~h5+Y|O(VB#E~5XuuXCZ5EAa!cKHx7jo#t0rU}l^F&|^ zHi|e*Bp$*r9>WM8$Fn$26n+lR;}xRtt9T8k@DAR^X(IC(qVgyB6rT~9zrlC7G>N)x z6RC^K(^0pab8XA950Y-2@)O;n5o5Ci2#fjsziH;*|0Ad(1R@0f#|WUJG1r)(1ZR3x z^1F7DYClz8xZQ}5feSUsLo&S@*#75_T JK*(F9`5TA7SFiv8 diff --git a/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py b/LeetCode/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py similarity index 100% rename from 1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py rename to LeetCode/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py diff --git a/1588_SumOfAllOddLengthSubarrays.py b/LeetCode/1588_SumOfAllOddLengthSubarrays.py similarity index 100% rename from 1588_SumOfAllOddLengthSubarrays.py rename to LeetCode/1588_SumOfAllOddLengthSubarrays.py From e07c949a958c9f76a699b9c5f3cdb9f43f0df855 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Thu, 29 Oct 2020 10:30:26 +0100 Subject: [PATCH 129/161] Delete 0001_Two_Sum.py --- LeetCode/0001_Two_Sum.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 LeetCode/0001_Two_Sum.py diff --git a/LeetCode/0001_Two_Sum.py b/LeetCode/0001_Two_Sum.py deleted file mode 100644 index 38a449c..0000000 --- a/LeetCode/0001_Two_Sum.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def twoSum(self, nums, target): - if len(nums) <= 1: - return False - buff_dict = {} - for i in range(len(nums)): - if nums[i] in buff_dict: - return [buff_dict[nums[i]], i] - else: - buff_dict[target - nums[i]] = i \ No newline at end of file From 0e514d5a74e470ddfb1449a4448406a60a95c92d Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Thu, 29 Oct 2020 10:38:34 +0100 Subject: [PATCH 130/161] Update leetcodeChecker.yml --- .github/workflows/leetcodeChecker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/leetcodeChecker.yml b/.github/workflows/leetcodeChecker.yml index d1f7d96..2ca45a3 100644 --- a/.github/workflows/leetcodeChecker.yml +++ b/.github/workflows/leetcodeChecker.yml @@ -22,7 +22,7 @@ jobs: run: | python leetcodeChecker.py env: - GITHUB_ACCESS_TOKEN: ${{ github.token }} + GITHUB_ACCESS_TOKEN: ${{ github.TOKEN }} REPO_NAME: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }} LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }} From 9b25f3c014a4cf60dbe56f48394c25703be54314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Kiglics?= Date: Thu, 29 Oct 2020 11:33:23 +0100 Subject: [PATCH 131/161] Word search II solution --- LeetCode/0212_Word_search_II.py | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 LeetCode/0212_Word_search_II.py diff --git a/LeetCode/0212_Word_search_II.py b/LeetCode/0212_Word_search_II.py new file mode 100644 index 0000000..b68f79d --- /dev/null +++ b/LeetCode/0212_Word_search_II.py @@ -0,0 +1,58 @@ +class Solution: + def neighbours(self, i): + n = [] + if i >= self.cols: + n.append(i-self.cols) + if i + self.cols < self.rows * self.cols: + n.append(i+self.cols) + if i % self.cols > 0: + n.append(i-1) + if i % self.cols < self.cols - 1: + n.append(i+1) + return n + + def search(self, s): + if len(self.words) == 0: + return False + l = 0 + r = len(self.words) - 1 + while l <= r-1: + c = (l+r)//2 + if self.words[c] < s: + l = c+1 + else: + r = c + if len(self.words[l]) < len(s): + return False + return self.words[l][:len(s)] == s + + def DFS(self, v, s): + if not self.search(s): + return + if s in self.words and s not in self.found: + self.found.append(s) + ne = self.neighbours(v) + for n in ne: + if self.used[n]: + continue + self.used[n] = True + self.DFS(n, s + self.board[n]) + self.used[n] = False + + + def findWords(self, board, words): + self.found = [] + self.words = sorted(words) + self.rows = len(board) + self.cols = len(board[0]) + self.board = [board[i][j] for i in range(len(board)) for j in range(len(board[0]))] + self.used = [False] * self.cols * self.rows + for i in range(len(self.board)): + self.used[i] = True + self.DFS(i, self.board[i]) + self.used[i] = False + return self.found + +# print(Solution().findWords([["a","a","a","a"],["a","a","a","a"],["a","a","a","a"],["a","a","a","a"],["b","c","d","e"],["f","g","h","i"],["j","k","l","m"],["n","o","p","q"],["r","s","t","u"],["v","w","x","y"],["z","z","z","z"]],["aaaaaaaaaaaaaaaa","aaaaaaaaaaaaaaab","aaaaaaaaaaaaaaac","aaaaaaaaaaaaaaad","aaaaaaaaaaaaaaae","aaaaaaaaaaaaaaaf","aaaaaaaaaaaaaaag","aaaaaaaaaaaaaaah","aaaaaaaaaaaaaaai","aaaaaaaaaaaaaaaj","aaaaaaaaaaaaaaak","aaaaaaaaaaaaaaal","aaaaaaaaaaaaaaam","aaaaaaaaaaaaaaan","aaaaaaaaaaaaaaao","aaaaaaaaaaaaaaap","aaaaaaaaaaaaaaaq","aaaaaaaaaaaaaaar","aaaaaaaaaaaaaaas","aaaaaaaaaaaaaaat","aaaaaaaaaaaaaaau","aaaaaaaaaaaaaaav","aaaaaaaaaaaaaaaw","aaaaaaaaaaaaaaax","aaaaaaaaaaaaaaay","aaaaaaaaaaaaaaaz","aaaaaaaaaaaaaaba","aaaaaaaaaaaaaabb","aaaaaaaaaaaaaabc","aaaaaaaaaaaaaabd","aaaaaaaaaaaaaabe","aaaaaaaaaaaaaabf","aaaaaaaaaaaaaabg","aaaaaaaaaaaaaabh","aaaaaaaaaaaaaabi","aaaaaaaaaaaaaabj","aaaaaaaaaaaaaabk","aaaaaaaaaaaaaabl","aaaaaaaaaaaaaabm","aaaaaaaaaaaaaabn","aaaaaaaaaaaaaabo","aaaaaaaaaaaaaabp","aaaaaaaaaaaaaabq","aaaaaaaaaaaaaabr","aaaaaaaaaaaaaabs","aaaaaaaaaaaaaabt","aaaaaaaaaaaaaabu","aaaaaaaaaaaaaabv","aaaaaaaaaaaaaabw","aaaaaaaaaaaaaabx","aaaaaaaaaaaaaaby","aaaaaaaaaaaaaabz","aaaaaaaaaaaaaaca","aaaaaaaaaaaaaacb","aaaaaaaaaaaaaacc","aaaaaaaaaaaaaacd","aaaaaaaaaaaaaace","aaaaaaaaaaaaaacf","aaaaaaaaaaaaaacg","aaaaaaaaaaaaaach","aaaaaaaaaaaaaaci","aaaaaaaaaaaaaacj","aaaaaaaaaaaaaack","aaaaaaaaaaaaaacl","aaaaaaaaaaaaaacm","aaaaaaaaaaaaaacn","aaaaaaaaaaaaaaco","aaaaaaaaaaaaaacp","aaaaaaaaaaaaaacq","aaaaaaaaaaaaaacr","aaaaaaaaaaaaaacs","aaaaaaaaaaaaaact","aaaaaaaaaaaaaacu","aaaaaaaaaaaaaacv","aaaaaaaaaaaaaacw","aaaaaaaaaaaaaacx","aaaaaaaaaaaaaacy","aaaaaaaaaaaaaacz","aaaaaaaaaaaaaada","aaaaaaaaaaaaaadb","aaaaaaaaaaaaaadc","aaaaaaaaaaaaaadd","aaaaaaaaaaaaaade","aaaaaaaaaaaaaadf","aaaaaaaaaaaaaadg","aaaaaaaaaaaaaadh","aaaaaaaaaaaaaadi","aaaaaaaaaaaaaadj","aaaaaaaaaaaaaadk","aaaaaaaaaaaaaadl","aaaaaaaaaaaaaadm","aaaaaaaaaaaaaadn","aaaaaaaaaaaaaado","aaaaaaaaaaaaaadp","aaaaaaaaaaaaaadq","aaaaaaaaaaaaaadr","aaaaaaaaaaaaaads","aaaaaaaaaaaaaadt","aaaaaaaaaaaaaadu","aaaaaaaaaaaaaadv","aaaaaaaaaaaaaadw","aaaaaaaaaaaaaadx","aaaaaaaaaaaaaady","aaaaaaaaaaaaaadz","aaaaaaaaaaaaaaea","aaaaaaaaaaaaaaeb","aaaaaaaaaaaaaaec","aaaaaaaaaaaaaaed","aaaaaaaaaaaaaaee","aaaaaaaaaaaaaaef","aaaaaaaaaaaaaaeg","aaaaaaaaaaaaaaeh","aaaaaaaaaaaaaaei","aaaaaaaaaaaaaaej","aaaaaaaaaaaaaaek","aaaaaaaaaaaaaael","aaaaaaaaaaaaaaem","aaaaaaaaaaaaaaen","aaaaaaaaaaaaaaeo","aaaaaaaaaaaaaaep","aaaaaaaaaaaaaaeq","aaaaaaaaaaaaaaer","aaaaaaaaaaaaaaes","aaaaaaaaaaaaaaet","aaaaaaaaaaaaaaeu","aaaaaaaaaaaaaaev","aaaaaaaaaaaaaaew","aaaaaaaaaaaaaaex","aaaaaaaaaaaaaaey","aaaaaaaaaaaaaaez","aaaaaaaaaaaaaafa","aaaaaaaaaaaaaafb","aaaaaaaaaaaaaafc","aaaaaaaaaaaaaafd","aaaaaaaaaaaaaafe","aaaaaaaaaaaaaaff","aaaaaaaaaaaaaafg","aaaaaaaaaaaaaafh","aaaaaaaaaaaaaafi","aaaaaaaaaaaaaafj","aaaaaaaaaaaaaafk","aaaaaaaaaaaaaafl","aaaaaaaaaaaaaafm","aaaaaaaaaaaaaafn","aaaaaaaaaaaaaafo","aaaaaaaaaaaaaafp","aaaaaaaaaaaaaafq","aaaaaaaaaaaaaafr","aaaaaaaaaaaaaafs","aaaaaaaaaaaaaaft","aaaaaaaaaaaaaafu","aaaaaaaaaaaaaafv","aaaaaaaaaaaaaafw","aaaaaaaaaaaaaafx","aaaaaaaaaaaaaafy","aaaaaaaaaaaaaafz","aaaaaaaaaaaaaaga","aaaaaaaaaaaaaagb","aaaaaaaaaaaaaagc","aaaaaaaaaaaaaagd","aaaaaaaaaaaaaage","aaaaaaaaaaaaaagf","aaaaaaaaaaaaaagg","aaaaaaaaaaaaaagh","aaaaaaaaaaaaaagi","aaaaaaaaaaaaaagj","aaaaaaaaaaaaaagk","aaaaaaaaaaaaaagl","aaaaaaaaaaaaaagm","aaaaaaaaaaaaaagn","aaaaaaaaaaaaaago","aaaaaaaaaaaaaagp","aaaaaaaaaaaaaagq","aaaaaaaaaaaaaagr","aaaaaaaaaaaaaags","aaaaaaaaaaaaaagt","aaaaaaaaaaaaaagu","aaaaaaaaaaaaaagv","aaaaaaaaaaaaaagw","aaaaaaaaaaaaaagx","aaaaaaaaaaaaaagy","aaaaaaaaaaaaaagz","aaaaaaaaaaaaaaha","aaaaaaaaaaaaaahb","aaaaaaaaaaaaaahc","aaaaaaaaaaaaaahd","aaaaaaaaaaaaaahe","aaaaaaaaaaaaaahf","aaaaaaaaaaaaaahg","aaaaaaaaaaaaaahh","aaaaaaaaaaaaaahi","aaaaaaaaaaaaaahj","aaaaaaaaaaaaaahk","aaaaaaaaaaaaaahl","aaaaaaaaaaaaaahm","aaaaaaaaaaaaaahn","aaaaaaaaaaaaaaho","aaaaaaaaaaaaaahp","aaaaaaaaaaaaaahq","aaaaaaaaaaaaaahr","aaaaaaaaaaaaaahs","aaaaaaaaaaaaaaht","aaaaaaaaaaaaaahu","aaaaaaaaaaaaaahv","aaaaaaaaaaaaaahw","aaaaaaaaaaaaaahx","aaaaaaaaaaaaaahy","aaaaaaaaaaaaaahz","aaaaaaaaaaaaaaia","aaaaaaaaaaaaaaib","aaaaaaaaaaaaaaic","aaaaaaaaaaaaaaid","aaaaaaaaaaaaaaie","aaaaaaaaaaaaaaif","aaaaaaaaaaaaaaig","aaaaaaaaaaaaaaih","aaaaaaaaaaaaaaii","aaaaaaaaaaaaaaij","aaaaaaaaaaaaaaik","aaaaaaaaaaaaaail","aaaaaaaaaaaaaaim","aaaaaaaaaaaaaain","aaaaaaaaaaaaaaio","aaaaaaaaaaaaaaip","aaaaaaaaaaaaaaiq","aaaaaaaaaaaaaair","aaaaaaaaaaaaaais","aaaaaaaaaaaaaait","aaaaaaaaaaaaaaiu","aaaaaaaaaaaaaaiv","aaaaaaaaaaaaaaiw","aaaaaaaaaaaaaaix","aaaaaaaaaaaaaaiy","aaaaaaaaaaaaaaiz","aaaaaaaaaaaaaaja","aaaaaaaaaaaaaajb","aaaaaaaaaaaaaajc","aaaaaaaaaaaaaajd","aaaaaaaaaaaaaaje","aaaaaaaaaaaaaajf","aaaaaaaaaaaaaajg","aaaaaaaaaaaaaajh","aaaaaaaaaaaaaaji","aaaaaaaaaaaaaajj","aaaaaaaaaaaaaajk","aaaaaaaaaaaaaajl","aaaaaaaaaaaaaajm","aaaaaaaaaaaaaajn","aaaaaaaaaaaaaajo","aaaaaaaaaaaaaajp","aaaaaaaaaaaaaajq","aaaaaaaaaaaaaajr","aaaaaaaaaaaaaajs","aaaaaaaaaaaaaajt","aaaaaaaaaaaaaaju","aaaaaaaaaaaaaajv","aaaaaaaaaaaaaajw","aaaaaaaaaaaaaajx","aaaaaaaaaaaaaajy","aaaaaaaaaaaaaajz","aaaaaaaaaaaaaaka","aaaaaaaaaaaaaakb","aaaaaaaaaaaaaakc","aaaaaaaaaaaaaakd","aaaaaaaaaaaaaake","aaaaaaaaaaaaaakf","aaaaaaaaaaaaaakg","aaaaaaaaaaaaaakh","aaaaaaaaaaaaaaki","aaaaaaaaaaaaaakj","aaaaaaaaaaaaaakk","aaaaaaaaaaaaaakl","aaaaaaaaaaaaaakm","aaaaaaaaaaaaaakn","aaaaaaaaaaaaaako","aaaaaaaaaaaaaakp","aaaaaaaaaaaaaakq","aaaaaaaaaaaaaakr","aaaaaaaaaaaaaaks","aaaaaaaaaaaaaakt","aaaaaaaaaaaaaaku","aaaaaaaaaaaaaakv","aaaaaaaaaaaaaakw","aaaaaaaaaaaaaakx","aaaaaaaaaaaaaaky","aaaaaaaaaaaaaakz","aaaaaaaaaaaaaala","aaaaaaaaaaaaaalb","aaaaaaaaaaaaaalc","aaaaaaaaaaaaaald","aaaaaaaaaaaaaale","aaaaaaaaaaaaaalf","aaaaaaaaaaaaaalg","aaaaaaaaaaaaaalh","aaaaaaaaaaaaaali","aaaaaaaaaaaaaalj","aaaaaaaaaaaaaalk","aaaaaaaaaaaaaall","aaaaaaaaaaaaaalm","aaaaaaaaaaaaaaln","aaaaaaaaaaaaaalo","aaaaaaaaaaaaaalp","aaaaaaaaaaaaaalq","aaaaaaaaaaaaaalr","aaaaaaaaaaaaaals","aaaaaaaaaaaaaalt","aaaaaaaaaaaaaalu","aaaaaaaaaaaaaalv","aaaaaaaaaaaaaalw","aaaaaaaaaaaaaalx","aaaaaaaaaaaaaaly","aaaaaaaaaaaaaalz","aaaaaaaaaaaaaama","aaaaaaaaaaaaaamb","aaaaaaaaaaaaaamc","aaaaaaaaaaaaaamd","aaaaaaaaaaaaaame","aaaaaaaaaaaaaamf","aaaaaaaaaaaaaamg","aaaaaaaaaaaaaamh","aaaaaaaaaaaaaami","aaaaaaaaaaaaaamj","aaaaaaaaaaaaaamk","aaaaaaaaaaaaaaml","aaaaaaaaaaaaaamm","aaaaaaaaaaaaaamn","aaaaaaaaaaaaaamo","aaaaaaaaaaaaaamp","aaaaaaaaaaaaaamq","aaaaaaaaaaaaaamr","aaaaaaaaaaaaaams","aaaaaaaaaaaaaamt","aaaaaaaaaaaaaamu","aaaaaaaaaaaaaamv","aaaaaaaaaaaaaamw","aaaaaaaaaaaaaamx","aaaaaaaaaaaaaamy","aaaaaaaaaaaaaamz","aaaaaaaaaaaaaana","aaaaaaaaaaaaaanb","aaaaaaaaaaaaaanc","aaaaaaaaaaaaaand","aaaaaaaaaaaaaane","aaaaaaaaaaaaaanf","aaaaaaaaaaaaaang","aaaaaaaaaaaaaanh","aaaaaaaaaaaaaani","aaaaaaaaaaaaaanj","aaaaaaaaaaaaaank","aaaaaaaaaaaaaanl","aaaaaaaaaaaaaanm","aaaaaaaaaaaaaann","aaaaaaaaaaaaaano","aaaaaaaaaaaaaanp","aaaaaaaaaaaaaanq","aaaaaaaaaaaaaanr","aaaaaaaaaaaaaans","aaaaaaaaaaaaaant","aaaaaaaaaaaaaanu","aaaaaaaaaaaaaanv","aaaaaaaaaaaaaanw","aaaaaaaaaaaaaanx","aaaaaaaaaaaaaany","aaaaaaaaaaaaaanz","aaaaaaaaaaaaaaoa","aaaaaaaaaaaaaaob","aaaaaaaaaaaaaaoc","aaaaaaaaaaaaaaod","aaaaaaaaaaaaaaoe","aaaaaaaaaaaaaaof","aaaaaaaaaaaaaaog","aaaaaaaaaaaaaaoh","aaaaaaaaaaaaaaoi","aaaaaaaaaaaaaaoj","aaaaaaaaaaaaaaok","aaaaaaaaaaaaaaol","aaaaaaaaaaaaaaom","aaaaaaaaaaaaaaon","aaaaaaaaaaaaaaoo","aaaaaaaaaaaaaaop","aaaaaaaaaaaaaaoq","aaaaaaaaaaaaaaor","aaaaaaaaaaaaaaos","aaaaaaaaaaaaaaot","aaaaaaaaaaaaaaou","aaaaaaaaaaaaaaov","aaaaaaaaaaaaaaow","aaaaaaaaaaaaaaox","aaaaaaaaaaaaaaoy","aaaaaaaaaaaaaaoz","aaaaaaaaaaaaaapa","aaaaaaaaaaaaaapb","aaaaaaaaaaaaaapc","aaaaaaaaaaaaaapd","aaaaaaaaaaaaaape","aaaaaaaaaaaaaapf","aaaaaaaaaaaaaapg","aaaaaaaaaaaaaaph","aaaaaaaaaaaaaapi","aaaaaaaaaaaaaapj","aaaaaaaaaaaaaapk","aaaaaaaaaaaaaapl","aaaaaaaaaaaaaapm","aaaaaaaaaaaaaapn","aaaaaaaaaaaaaapo","aaaaaaaaaaaaaapp","aaaaaaaaaaaaaapq","aaaaaaaaaaaaaapr","aaaaaaaaaaaaaaps","aaaaaaaaaaaaaapt","aaaaaaaaaaaaaapu","aaaaaaaaaaaaaapv","aaaaaaaaaaaaaapw","aaaaaaaaaaaaaapx","aaaaaaaaaaaaaapy","aaaaaaaaaaaaaapz","aaaaaaaaaaaaaaqa","aaaaaaaaaaaaaaqb","aaaaaaaaaaaaaaqc","aaaaaaaaaaaaaaqd","aaaaaaaaaaaaaaqe","aaaaaaaaaaaaaaqf","aaaaaaaaaaaaaaqg","aaaaaaaaaaaaaaqh","aaaaaaaaaaaaaaqi","aaaaaaaaaaaaaaqj","aaaaaaaaaaaaaaqk","aaaaaaaaaaaaaaql","aaaaaaaaaaaaaaqm","aaaaaaaaaaaaaaqn","aaaaaaaaaaaaaaqo","aaaaaaaaaaaaaaqp","aaaaaaaaaaaaaaqq","aaaaaaaaaaaaaaqr","aaaaaaaaaaaaaaqs","aaaaaaaaaaaaaaqt","aaaaaaaaaaaaaaqu","aaaaaaaaaaaaaaqv","aaaaaaaaaaaaaaqw","aaaaaaaaaaaaaaqx","aaaaaaaaaaaaaaqy","aaaaaaaaaaaaaaqz","aaaaaaaaaaaaaara","aaaaaaaaaaaaaarb","aaaaaaaaaaaaaarc","aaaaaaaaaaaaaard","aaaaaaaaaaaaaare","aaaaaaaaaaaaaarf","aaaaaaaaaaaaaarg","aaaaaaaaaaaaaarh","aaaaaaaaaaaaaari","aaaaaaaaaaaaaarj","aaaaaaaaaaaaaark","aaaaaaaaaaaaaarl","aaaaaaaaaaaaaarm","aaaaaaaaaaaaaarn","aaaaaaaaaaaaaaro","aaaaaaaaaaaaaarp","aaaaaaaaaaaaaarq","aaaaaaaaaaaaaarr","aaaaaaaaaaaaaars","aaaaaaaaaaaaaart","aaaaaaaaaaaaaaru","aaaaaaaaaaaaaarv","aaaaaaaaaaaaaarw","aaaaaaaaaaaaaarx","aaaaaaaaaaaaaary","aaaaaaaaaaaaaarz","aaaaaaaaaaaaaasa","aaaaaaaaaaaaaasb","aaaaaaaaaaaaaasc","aaaaaaaaaaaaaasd","aaaaaaaaaaaaaase","aaaaaaaaaaaaaasf","aaaaaaaaaaaaaasg","aaaaaaaaaaaaaash","aaaaaaaaaaaaaasi","aaaaaaaaaaaaaasj","aaaaaaaaaaaaaask","aaaaaaaaaaaaaasl","aaaaaaaaaaaaaasm","aaaaaaaaaaaaaasn","aaaaaaaaaaaaaaso","aaaaaaaaaaaaaasp","aaaaaaaaaaaaaasq","aaaaaaaaaaaaaasr","aaaaaaaaaaaaaass","aaaaaaaaaaaaaast","aaaaaaaaaaaaaasu","aaaaaaaaaaaaaasv","aaaaaaaaaaaaaasw","aaaaaaaaaaaaaasx","aaaaaaaaaaaaaasy","aaaaaaaaaaaaaasz","aaaaaaaaaaaaaata","aaaaaaaaaaaaaatb","aaaaaaaaaaaaaatc","aaaaaaaaaaaaaatd","aaaaaaaaaaaaaate","aaaaaaaaaaaaaatf","aaaaaaaaaaaaaatg","aaaaaaaaaaaaaath","aaaaaaaaaaaaaati","aaaaaaaaaaaaaatj","aaaaaaaaaaaaaatk","aaaaaaaaaaaaaatl","aaaaaaaaaaaaaatm","aaaaaaaaaaaaaatn","aaaaaaaaaaaaaato","aaaaaaaaaaaaaatp","aaaaaaaaaaaaaatq","aaaaaaaaaaaaaatr","aaaaaaaaaaaaaats","aaaaaaaaaaaaaatt","aaaaaaaaaaaaaatu","aaaaaaaaaaaaaatv","aaaaaaaaaaaaaatw","aaaaaaaaaaaaaatx","aaaaaaaaaaaaaaty","aaaaaaaaaaaaaatz","aaaaaaaaaaaaaaua","aaaaaaaaaaaaaaub","aaaaaaaaaaaaaauc","aaaaaaaaaaaaaaud","aaaaaaaaaaaaaaue","aaaaaaaaaaaaaauf","aaaaaaaaaaaaaaug","aaaaaaaaaaaaaauh","aaaaaaaaaaaaaaui","aaaaaaaaaaaaaauj","aaaaaaaaaaaaaauk","aaaaaaaaaaaaaaul","aaaaaaaaaaaaaaum","aaaaaaaaaaaaaaun","aaaaaaaaaaaaaauo","aaaaaaaaaaaaaaup","aaaaaaaaaaaaaauq","aaaaaaaaaaaaaaur","aaaaaaaaaaaaaaus","aaaaaaaaaaaaaaut","aaaaaaaaaaaaaauu","aaaaaaaaaaaaaauv","aaaaaaaaaaaaaauw","aaaaaaaaaaaaaaux","aaaaaaaaaaaaaauy","aaaaaaaaaaaaaauz","aaaaaaaaaaaaaava","aaaaaaaaaaaaaavb","aaaaaaaaaaaaaavc","aaaaaaaaaaaaaavd","aaaaaaaaaaaaaave","aaaaaaaaaaaaaavf","aaaaaaaaaaaaaavg","aaaaaaaaaaaaaavh","aaaaaaaaaaaaaavi","aaaaaaaaaaaaaavj","aaaaaaaaaaaaaavk","aaaaaaaaaaaaaavl","aaaaaaaaaaaaaavm","aaaaaaaaaaaaaavn","aaaaaaaaaaaaaavo","aaaaaaaaaaaaaavp","aaaaaaaaaaaaaavq","aaaaaaaaaaaaaavr","aaaaaaaaaaaaaavs","aaaaaaaaaaaaaavt","aaaaaaaaaaaaaavu","aaaaaaaaaaaaaavv","aaaaaaaaaaaaaavw","aaaaaaaaaaaaaavx","aaaaaaaaaaaaaavy","aaaaaaaaaaaaaavz","aaaaaaaaaaaaaawa","aaaaaaaaaaaaaawb","aaaaaaaaaaaaaawc","aaaaaaaaaaaaaawd","aaaaaaaaaaaaaawe","aaaaaaaaaaaaaawf","aaaaaaaaaaaaaawg","aaaaaaaaaaaaaawh","aaaaaaaaaaaaaawi","aaaaaaaaaaaaaawj","aaaaaaaaaaaaaawk","aaaaaaaaaaaaaawl","aaaaaaaaaaaaaawm","aaaaaaaaaaaaaawn","aaaaaaaaaaaaaawo","aaaaaaaaaaaaaawp","aaaaaaaaaaaaaawq","aaaaaaaaaaaaaawr","aaaaaaaaaaaaaaws","aaaaaaaaaaaaaawt","aaaaaaaaaaaaaawu","aaaaaaaaaaaaaawv","aaaaaaaaaaaaaaww","aaaaaaaaaaaaaawx","aaaaaaaaaaaaaawy","aaaaaaaaaaaaaawz","aaaaaaaaaaaaaaxa","aaaaaaaaaaaaaaxb","aaaaaaaaaaaaaaxc","aaaaaaaaaaaaaaxd","aaaaaaaaaaaaaaxe","aaaaaaaaaaaaaaxf","aaaaaaaaaaaaaaxg","aaaaaaaaaaaaaaxh","aaaaaaaaaaaaaaxi","aaaaaaaaaaaaaaxj","aaaaaaaaaaaaaaxk","aaaaaaaaaaaaaaxl","aaaaaaaaaaaaaaxm","aaaaaaaaaaaaaaxn","aaaaaaaaaaaaaaxo","aaaaaaaaaaaaaaxp","aaaaaaaaaaaaaaxq","aaaaaaaaaaaaaaxr","aaaaaaaaaaaaaaxs","aaaaaaaaaaaaaaxt","aaaaaaaaaaaaaaxu","aaaaaaaaaaaaaaxv","aaaaaaaaaaaaaaxw","aaaaaaaaaaaaaaxx","aaaaaaaaaaaaaaxy","aaaaaaaaaaaaaaxz","aaaaaaaaaaaaaaya","aaaaaaaaaaaaaayb","aaaaaaaaaaaaaayc","aaaaaaaaaaaaaayd","aaaaaaaaaaaaaaye","aaaaaaaaaaaaaayf","aaaaaaaaaaaaaayg","aaaaaaaaaaaaaayh","aaaaaaaaaaaaaayi","aaaaaaaaaaaaaayj","aaaaaaaaaaaaaayk","aaaaaaaaaaaaaayl","aaaaaaaaaaaaaaym","aaaaaaaaaaaaaayn","aaaaaaaaaaaaaayo","aaaaaaaaaaaaaayp","aaaaaaaaaaaaaayq","aaaaaaaaaaaaaayr","aaaaaaaaaaaaaays","aaaaaaaaaaaaaayt","aaaaaaaaaaaaaayu","aaaaaaaaaaaaaayv","aaaaaaaaaaaaaayw","aaaaaaaaaaaaaayx","aaaaaaaaaaaaaayy","aaaaaaaaaaaaaayz","aaaaaaaaaaaaaaza","aaaaaaaaaaaaaazb","aaaaaaaaaaaaaazc","aaaaaaaaaaaaaazd","aaaaaaaaaaaaaaze","aaaaaaaaaaaaaazf","aaaaaaaaaaaaaazg","aaaaaaaaaaaaaazh","aaaaaaaaaaaaaazi","aaaaaaaaaaaaaazj","aaaaaaaaaaaaaazk","aaaaaaaaaaaaaazl","aaaaaaaaaaaaaazm","aaaaaaaaaaaaaazn","aaaaaaaaaaaaaazo","aaaaaaaaaaaaaazp","aaaaaaaaaaaaaazq","aaaaaaaaaaaaaazr","aaaaaaaaaaaaaazs","aaaaaaaaaaaaaazt","aaaaaaaaaaaaaazu","aaaaaaaaaaaaaazv","aaaaaaaaaaaaaazw","aaaaaaaaaaaaaazx","aaaaaaaaaaaaaazy","aaaaaaaaaaaaaazz"])) +print(Solution().findWords([['o','a','a','n'],['e','t','a','e'],['i','h','k','r'],['i','f','l','v']],["oath","pea","eat","rain"])) +print(Solution().findWords([['a']], [])) \ No newline at end of file From 7f7c016af246fb475cbc77626cfcc84326c2d7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Kiglics?= Date: Thu, 29 Oct 2020 11:37:07 +0100 Subject: [PATCH 132/161] Word search II delete test lines --- LeetCode/0212_Word_search_II.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/LeetCode/0212_Word_search_II.py b/LeetCode/0212_Word_search_II.py index b68f79d..3c5de35 100644 --- a/LeetCode/0212_Word_search_II.py +++ b/LeetCode/0212_Word_search_II.py @@ -53,6 +53,3 @@ def findWords(self, board, words): self.used[i] = False return self.found -# print(Solution().findWords([["a","a","a","a"],["a","a","a","a"],["a","a","a","a"],["a","a","a","a"],["b","c","d","e"],["f","g","h","i"],["j","k","l","m"],["n","o","p","q"],["r","s","t","u"],["v","w","x","y"],["z","z","z","z"]],["aaaaaaaaaaaaaaaa","aaaaaaaaaaaaaaab","aaaaaaaaaaaaaaac","aaaaaaaaaaaaaaad","aaaaaaaaaaaaaaae","aaaaaaaaaaaaaaaf","aaaaaaaaaaaaaaag","aaaaaaaaaaaaaaah","aaaaaaaaaaaaaaai","aaaaaaaaaaaaaaaj","aaaaaaaaaaaaaaak","aaaaaaaaaaaaaaal","aaaaaaaaaaaaaaam","aaaaaaaaaaaaaaan","aaaaaaaaaaaaaaao","aaaaaaaaaaaaaaap","aaaaaaaaaaaaaaaq","aaaaaaaaaaaaaaar","aaaaaaaaaaaaaaas","aaaaaaaaaaaaaaat","aaaaaaaaaaaaaaau","aaaaaaaaaaaaaaav","aaaaaaaaaaaaaaaw","aaaaaaaaaaaaaaax","aaaaaaaaaaaaaaay","aaaaaaaaaaaaaaaz","aaaaaaaaaaaaaaba","aaaaaaaaaaaaaabb","aaaaaaaaaaaaaabc","aaaaaaaaaaaaaabd","aaaaaaaaaaaaaabe","aaaaaaaaaaaaaabf","aaaaaaaaaaaaaabg","aaaaaaaaaaaaaabh","aaaaaaaaaaaaaabi","aaaaaaaaaaaaaabj","aaaaaaaaaaaaaabk","aaaaaaaaaaaaaabl","aaaaaaaaaaaaaabm","aaaaaaaaaaaaaabn","aaaaaaaaaaaaaabo","aaaaaaaaaaaaaabp","aaaaaaaaaaaaaabq","aaaaaaaaaaaaaabr","aaaaaaaaaaaaaabs","aaaaaaaaaaaaaabt","aaaaaaaaaaaaaabu","aaaaaaaaaaaaaabv","aaaaaaaaaaaaaabw","aaaaaaaaaaaaaabx","aaaaaaaaaaaaaaby","aaaaaaaaaaaaaabz","aaaaaaaaaaaaaaca","aaaaaaaaaaaaaacb","aaaaaaaaaaaaaacc","aaaaaaaaaaaaaacd","aaaaaaaaaaaaaace","aaaaaaaaaaaaaacf","aaaaaaaaaaaaaacg","aaaaaaaaaaaaaach","aaaaaaaaaaaaaaci","aaaaaaaaaaaaaacj","aaaaaaaaaaaaaack","aaaaaaaaaaaaaacl","aaaaaaaaaaaaaacm","aaaaaaaaaaaaaacn","aaaaaaaaaaaaaaco","aaaaaaaaaaaaaacp","aaaaaaaaaaaaaacq","aaaaaaaaaaaaaacr","aaaaaaaaaaaaaacs","aaaaaaaaaaaaaact","aaaaaaaaaaaaaacu","aaaaaaaaaaaaaacv","aaaaaaaaaaaaaacw","aaaaaaaaaaaaaacx","aaaaaaaaaaaaaacy","aaaaaaaaaaaaaacz","aaaaaaaaaaaaaada","aaaaaaaaaaaaaadb","aaaaaaaaaaaaaadc","aaaaaaaaaaaaaadd","aaaaaaaaaaaaaade","aaaaaaaaaaaaaadf","aaaaaaaaaaaaaadg","aaaaaaaaaaaaaadh","aaaaaaaaaaaaaadi","aaaaaaaaaaaaaadj","aaaaaaaaaaaaaadk","aaaaaaaaaaaaaadl","aaaaaaaaaaaaaadm","aaaaaaaaaaaaaadn","aaaaaaaaaaaaaado","aaaaaaaaaaaaaadp","aaaaaaaaaaaaaadq","aaaaaaaaaaaaaadr","aaaaaaaaaaaaaads","aaaaaaaaaaaaaadt","aaaaaaaaaaaaaadu","aaaaaaaaaaaaaadv","aaaaaaaaaaaaaadw","aaaaaaaaaaaaaadx","aaaaaaaaaaaaaady","aaaaaaaaaaaaaadz","aaaaaaaaaaaaaaea","aaaaaaaaaaaaaaeb","aaaaaaaaaaaaaaec","aaaaaaaaaaaaaaed","aaaaaaaaaaaaaaee","aaaaaaaaaaaaaaef","aaaaaaaaaaaaaaeg","aaaaaaaaaaaaaaeh","aaaaaaaaaaaaaaei","aaaaaaaaaaaaaaej","aaaaaaaaaaaaaaek","aaaaaaaaaaaaaael","aaaaaaaaaaaaaaem","aaaaaaaaaaaaaaen","aaaaaaaaaaaaaaeo","aaaaaaaaaaaaaaep","aaaaaaaaaaaaaaeq","aaaaaaaaaaaaaaer","aaaaaaaaaaaaaaes","aaaaaaaaaaaaaaet","aaaaaaaaaaaaaaeu","aaaaaaaaaaaaaaev","aaaaaaaaaaaaaaew","aaaaaaaaaaaaaaex","aaaaaaaaaaaaaaey","aaaaaaaaaaaaaaez","aaaaaaaaaaaaaafa","aaaaaaaaaaaaaafb","aaaaaaaaaaaaaafc","aaaaaaaaaaaaaafd","aaaaaaaaaaaaaafe","aaaaaaaaaaaaaaff","aaaaaaaaaaaaaafg","aaaaaaaaaaaaaafh","aaaaaaaaaaaaaafi","aaaaaaaaaaaaaafj","aaaaaaaaaaaaaafk","aaaaaaaaaaaaaafl","aaaaaaaaaaaaaafm","aaaaaaaaaaaaaafn","aaaaaaaaaaaaaafo","aaaaaaaaaaaaaafp","aaaaaaaaaaaaaafq","aaaaaaaaaaaaaafr","aaaaaaaaaaaaaafs","aaaaaaaaaaaaaaft","aaaaaaaaaaaaaafu","aaaaaaaaaaaaaafv","aaaaaaaaaaaaaafw","aaaaaaaaaaaaaafx","aaaaaaaaaaaaaafy","aaaaaaaaaaaaaafz","aaaaaaaaaaaaaaga","aaaaaaaaaaaaaagb","aaaaaaaaaaaaaagc","aaaaaaaaaaaaaagd","aaaaaaaaaaaaaage","aaaaaaaaaaaaaagf","aaaaaaaaaaaaaagg","aaaaaaaaaaaaaagh","aaaaaaaaaaaaaagi","aaaaaaaaaaaaaagj","aaaaaaaaaaaaaagk","aaaaaaaaaaaaaagl","aaaaaaaaaaaaaagm","aaaaaaaaaaaaaagn","aaaaaaaaaaaaaago","aaaaaaaaaaaaaagp","aaaaaaaaaaaaaagq","aaaaaaaaaaaaaagr","aaaaaaaaaaaaaags","aaaaaaaaaaaaaagt","aaaaaaaaaaaaaagu","aaaaaaaaaaaaaagv","aaaaaaaaaaaaaagw","aaaaaaaaaaaaaagx","aaaaaaaaaaaaaagy","aaaaaaaaaaaaaagz","aaaaaaaaaaaaaaha","aaaaaaaaaaaaaahb","aaaaaaaaaaaaaahc","aaaaaaaaaaaaaahd","aaaaaaaaaaaaaahe","aaaaaaaaaaaaaahf","aaaaaaaaaaaaaahg","aaaaaaaaaaaaaahh","aaaaaaaaaaaaaahi","aaaaaaaaaaaaaahj","aaaaaaaaaaaaaahk","aaaaaaaaaaaaaahl","aaaaaaaaaaaaaahm","aaaaaaaaaaaaaahn","aaaaaaaaaaaaaaho","aaaaaaaaaaaaaahp","aaaaaaaaaaaaaahq","aaaaaaaaaaaaaahr","aaaaaaaaaaaaaahs","aaaaaaaaaaaaaaht","aaaaaaaaaaaaaahu","aaaaaaaaaaaaaahv","aaaaaaaaaaaaaahw","aaaaaaaaaaaaaahx","aaaaaaaaaaaaaahy","aaaaaaaaaaaaaahz","aaaaaaaaaaaaaaia","aaaaaaaaaaaaaaib","aaaaaaaaaaaaaaic","aaaaaaaaaaaaaaid","aaaaaaaaaaaaaaie","aaaaaaaaaaaaaaif","aaaaaaaaaaaaaaig","aaaaaaaaaaaaaaih","aaaaaaaaaaaaaaii","aaaaaaaaaaaaaaij","aaaaaaaaaaaaaaik","aaaaaaaaaaaaaail","aaaaaaaaaaaaaaim","aaaaaaaaaaaaaain","aaaaaaaaaaaaaaio","aaaaaaaaaaaaaaip","aaaaaaaaaaaaaaiq","aaaaaaaaaaaaaair","aaaaaaaaaaaaaais","aaaaaaaaaaaaaait","aaaaaaaaaaaaaaiu","aaaaaaaaaaaaaaiv","aaaaaaaaaaaaaaiw","aaaaaaaaaaaaaaix","aaaaaaaaaaaaaaiy","aaaaaaaaaaaaaaiz","aaaaaaaaaaaaaaja","aaaaaaaaaaaaaajb","aaaaaaaaaaaaaajc","aaaaaaaaaaaaaajd","aaaaaaaaaaaaaaje","aaaaaaaaaaaaaajf","aaaaaaaaaaaaaajg","aaaaaaaaaaaaaajh","aaaaaaaaaaaaaaji","aaaaaaaaaaaaaajj","aaaaaaaaaaaaaajk","aaaaaaaaaaaaaajl","aaaaaaaaaaaaaajm","aaaaaaaaaaaaaajn","aaaaaaaaaaaaaajo","aaaaaaaaaaaaaajp","aaaaaaaaaaaaaajq","aaaaaaaaaaaaaajr","aaaaaaaaaaaaaajs","aaaaaaaaaaaaaajt","aaaaaaaaaaaaaaju","aaaaaaaaaaaaaajv","aaaaaaaaaaaaaajw","aaaaaaaaaaaaaajx","aaaaaaaaaaaaaajy","aaaaaaaaaaaaaajz","aaaaaaaaaaaaaaka","aaaaaaaaaaaaaakb","aaaaaaaaaaaaaakc","aaaaaaaaaaaaaakd","aaaaaaaaaaaaaake","aaaaaaaaaaaaaakf","aaaaaaaaaaaaaakg","aaaaaaaaaaaaaakh","aaaaaaaaaaaaaaki","aaaaaaaaaaaaaakj","aaaaaaaaaaaaaakk","aaaaaaaaaaaaaakl","aaaaaaaaaaaaaakm","aaaaaaaaaaaaaakn","aaaaaaaaaaaaaako","aaaaaaaaaaaaaakp","aaaaaaaaaaaaaakq","aaaaaaaaaaaaaakr","aaaaaaaaaaaaaaks","aaaaaaaaaaaaaakt","aaaaaaaaaaaaaaku","aaaaaaaaaaaaaakv","aaaaaaaaaaaaaakw","aaaaaaaaaaaaaakx","aaaaaaaaaaaaaaky","aaaaaaaaaaaaaakz","aaaaaaaaaaaaaala","aaaaaaaaaaaaaalb","aaaaaaaaaaaaaalc","aaaaaaaaaaaaaald","aaaaaaaaaaaaaale","aaaaaaaaaaaaaalf","aaaaaaaaaaaaaalg","aaaaaaaaaaaaaalh","aaaaaaaaaaaaaali","aaaaaaaaaaaaaalj","aaaaaaaaaaaaaalk","aaaaaaaaaaaaaall","aaaaaaaaaaaaaalm","aaaaaaaaaaaaaaln","aaaaaaaaaaaaaalo","aaaaaaaaaaaaaalp","aaaaaaaaaaaaaalq","aaaaaaaaaaaaaalr","aaaaaaaaaaaaaals","aaaaaaaaaaaaaalt","aaaaaaaaaaaaaalu","aaaaaaaaaaaaaalv","aaaaaaaaaaaaaalw","aaaaaaaaaaaaaalx","aaaaaaaaaaaaaaly","aaaaaaaaaaaaaalz","aaaaaaaaaaaaaama","aaaaaaaaaaaaaamb","aaaaaaaaaaaaaamc","aaaaaaaaaaaaaamd","aaaaaaaaaaaaaame","aaaaaaaaaaaaaamf","aaaaaaaaaaaaaamg","aaaaaaaaaaaaaamh","aaaaaaaaaaaaaami","aaaaaaaaaaaaaamj","aaaaaaaaaaaaaamk","aaaaaaaaaaaaaaml","aaaaaaaaaaaaaamm","aaaaaaaaaaaaaamn","aaaaaaaaaaaaaamo","aaaaaaaaaaaaaamp","aaaaaaaaaaaaaamq","aaaaaaaaaaaaaamr","aaaaaaaaaaaaaams","aaaaaaaaaaaaaamt","aaaaaaaaaaaaaamu","aaaaaaaaaaaaaamv","aaaaaaaaaaaaaamw","aaaaaaaaaaaaaamx","aaaaaaaaaaaaaamy","aaaaaaaaaaaaaamz","aaaaaaaaaaaaaana","aaaaaaaaaaaaaanb","aaaaaaaaaaaaaanc","aaaaaaaaaaaaaand","aaaaaaaaaaaaaane","aaaaaaaaaaaaaanf","aaaaaaaaaaaaaang","aaaaaaaaaaaaaanh","aaaaaaaaaaaaaani","aaaaaaaaaaaaaanj","aaaaaaaaaaaaaank","aaaaaaaaaaaaaanl","aaaaaaaaaaaaaanm","aaaaaaaaaaaaaann","aaaaaaaaaaaaaano","aaaaaaaaaaaaaanp","aaaaaaaaaaaaaanq","aaaaaaaaaaaaaanr","aaaaaaaaaaaaaans","aaaaaaaaaaaaaant","aaaaaaaaaaaaaanu","aaaaaaaaaaaaaanv","aaaaaaaaaaaaaanw","aaaaaaaaaaaaaanx","aaaaaaaaaaaaaany","aaaaaaaaaaaaaanz","aaaaaaaaaaaaaaoa","aaaaaaaaaaaaaaob","aaaaaaaaaaaaaaoc","aaaaaaaaaaaaaaod","aaaaaaaaaaaaaaoe","aaaaaaaaaaaaaaof","aaaaaaaaaaaaaaog","aaaaaaaaaaaaaaoh","aaaaaaaaaaaaaaoi","aaaaaaaaaaaaaaoj","aaaaaaaaaaaaaaok","aaaaaaaaaaaaaaol","aaaaaaaaaaaaaaom","aaaaaaaaaaaaaaon","aaaaaaaaaaaaaaoo","aaaaaaaaaaaaaaop","aaaaaaaaaaaaaaoq","aaaaaaaaaaaaaaor","aaaaaaaaaaaaaaos","aaaaaaaaaaaaaaot","aaaaaaaaaaaaaaou","aaaaaaaaaaaaaaov","aaaaaaaaaaaaaaow","aaaaaaaaaaaaaaox","aaaaaaaaaaaaaaoy","aaaaaaaaaaaaaaoz","aaaaaaaaaaaaaapa","aaaaaaaaaaaaaapb","aaaaaaaaaaaaaapc","aaaaaaaaaaaaaapd","aaaaaaaaaaaaaape","aaaaaaaaaaaaaapf","aaaaaaaaaaaaaapg","aaaaaaaaaaaaaaph","aaaaaaaaaaaaaapi","aaaaaaaaaaaaaapj","aaaaaaaaaaaaaapk","aaaaaaaaaaaaaapl","aaaaaaaaaaaaaapm","aaaaaaaaaaaaaapn","aaaaaaaaaaaaaapo","aaaaaaaaaaaaaapp","aaaaaaaaaaaaaapq","aaaaaaaaaaaaaapr","aaaaaaaaaaaaaaps","aaaaaaaaaaaaaapt","aaaaaaaaaaaaaapu","aaaaaaaaaaaaaapv","aaaaaaaaaaaaaapw","aaaaaaaaaaaaaapx","aaaaaaaaaaaaaapy","aaaaaaaaaaaaaapz","aaaaaaaaaaaaaaqa","aaaaaaaaaaaaaaqb","aaaaaaaaaaaaaaqc","aaaaaaaaaaaaaaqd","aaaaaaaaaaaaaaqe","aaaaaaaaaaaaaaqf","aaaaaaaaaaaaaaqg","aaaaaaaaaaaaaaqh","aaaaaaaaaaaaaaqi","aaaaaaaaaaaaaaqj","aaaaaaaaaaaaaaqk","aaaaaaaaaaaaaaql","aaaaaaaaaaaaaaqm","aaaaaaaaaaaaaaqn","aaaaaaaaaaaaaaqo","aaaaaaaaaaaaaaqp","aaaaaaaaaaaaaaqq","aaaaaaaaaaaaaaqr","aaaaaaaaaaaaaaqs","aaaaaaaaaaaaaaqt","aaaaaaaaaaaaaaqu","aaaaaaaaaaaaaaqv","aaaaaaaaaaaaaaqw","aaaaaaaaaaaaaaqx","aaaaaaaaaaaaaaqy","aaaaaaaaaaaaaaqz","aaaaaaaaaaaaaara","aaaaaaaaaaaaaarb","aaaaaaaaaaaaaarc","aaaaaaaaaaaaaard","aaaaaaaaaaaaaare","aaaaaaaaaaaaaarf","aaaaaaaaaaaaaarg","aaaaaaaaaaaaaarh","aaaaaaaaaaaaaari","aaaaaaaaaaaaaarj","aaaaaaaaaaaaaark","aaaaaaaaaaaaaarl","aaaaaaaaaaaaaarm","aaaaaaaaaaaaaarn","aaaaaaaaaaaaaaro","aaaaaaaaaaaaaarp","aaaaaaaaaaaaaarq","aaaaaaaaaaaaaarr","aaaaaaaaaaaaaars","aaaaaaaaaaaaaart","aaaaaaaaaaaaaaru","aaaaaaaaaaaaaarv","aaaaaaaaaaaaaarw","aaaaaaaaaaaaaarx","aaaaaaaaaaaaaary","aaaaaaaaaaaaaarz","aaaaaaaaaaaaaasa","aaaaaaaaaaaaaasb","aaaaaaaaaaaaaasc","aaaaaaaaaaaaaasd","aaaaaaaaaaaaaase","aaaaaaaaaaaaaasf","aaaaaaaaaaaaaasg","aaaaaaaaaaaaaash","aaaaaaaaaaaaaasi","aaaaaaaaaaaaaasj","aaaaaaaaaaaaaask","aaaaaaaaaaaaaasl","aaaaaaaaaaaaaasm","aaaaaaaaaaaaaasn","aaaaaaaaaaaaaaso","aaaaaaaaaaaaaasp","aaaaaaaaaaaaaasq","aaaaaaaaaaaaaasr","aaaaaaaaaaaaaass","aaaaaaaaaaaaaast","aaaaaaaaaaaaaasu","aaaaaaaaaaaaaasv","aaaaaaaaaaaaaasw","aaaaaaaaaaaaaasx","aaaaaaaaaaaaaasy","aaaaaaaaaaaaaasz","aaaaaaaaaaaaaata","aaaaaaaaaaaaaatb","aaaaaaaaaaaaaatc","aaaaaaaaaaaaaatd","aaaaaaaaaaaaaate","aaaaaaaaaaaaaatf","aaaaaaaaaaaaaatg","aaaaaaaaaaaaaath","aaaaaaaaaaaaaati","aaaaaaaaaaaaaatj","aaaaaaaaaaaaaatk","aaaaaaaaaaaaaatl","aaaaaaaaaaaaaatm","aaaaaaaaaaaaaatn","aaaaaaaaaaaaaato","aaaaaaaaaaaaaatp","aaaaaaaaaaaaaatq","aaaaaaaaaaaaaatr","aaaaaaaaaaaaaats","aaaaaaaaaaaaaatt","aaaaaaaaaaaaaatu","aaaaaaaaaaaaaatv","aaaaaaaaaaaaaatw","aaaaaaaaaaaaaatx","aaaaaaaaaaaaaaty","aaaaaaaaaaaaaatz","aaaaaaaaaaaaaaua","aaaaaaaaaaaaaaub","aaaaaaaaaaaaaauc","aaaaaaaaaaaaaaud","aaaaaaaaaaaaaaue","aaaaaaaaaaaaaauf","aaaaaaaaaaaaaaug","aaaaaaaaaaaaaauh","aaaaaaaaaaaaaaui","aaaaaaaaaaaaaauj","aaaaaaaaaaaaaauk","aaaaaaaaaaaaaaul","aaaaaaaaaaaaaaum","aaaaaaaaaaaaaaun","aaaaaaaaaaaaaauo","aaaaaaaaaaaaaaup","aaaaaaaaaaaaaauq","aaaaaaaaaaaaaaur","aaaaaaaaaaaaaaus","aaaaaaaaaaaaaaut","aaaaaaaaaaaaaauu","aaaaaaaaaaaaaauv","aaaaaaaaaaaaaauw","aaaaaaaaaaaaaaux","aaaaaaaaaaaaaauy","aaaaaaaaaaaaaauz","aaaaaaaaaaaaaava","aaaaaaaaaaaaaavb","aaaaaaaaaaaaaavc","aaaaaaaaaaaaaavd","aaaaaaaaaaaaaave","aaaaaaaaaaaaaavf","aaaaaaaaaaaaaavg","aaaaaaaaaaaaaavh","aaaaaaaaaaaaaavi","aaaaaaaaaaaaaavj","aaaaaaaaaaaaaavk","aaaaaaaaaaaaaavl","aaaaaaaaaaaaaavm","aaaaaaaaaaaaaavn","aaaaaaaaaaaaaavo","aaaaaaaaaaaaaavp","aaaaaaaaaaaaaavq","aaaaaaaaaaaaaavr","aaaaaaaaaaaaaavs","aaaaaaaaaaaaaavt","aaaaaaaaaaaaaavu","aaaaaaaaaaaaaavv","aaaaaaaaaaaaaavw","aaaaaaaaaaaaaavx","aaaaaaaaaaaaaavy","aaaaaaaaaaaaaavz","aaaaaaaaaaaaaawa","aaaaaaaaaaaaaawb","aaaaaaaaaaaaaawc","aaaaaaaaaaaaaawd","aaaaaaaaaaaaaawe","aaaaaaaaaaaaaawf","aaaaaaaaaaaaaawg","aaaaaaaaaaaaaawh","aaaaaaaaaaaaaawi","aaaaaaaaaaaaaawj","aaaaaaaaaaaaaawk","aaaaaaaaaaaaaawl","aaaaaaaaaaaaaawm","aaaaaaaaaaaaaawn","aaaaaaaaaaaaaawo","aaaaaaaaaaaaaawp","aaaaaaaaaaaaaawq","aaaaaaaaaaaaaawr","aaaaaaaaaaaaaaws","aaaaaaaaaaaaaawt","aaaaaaaaaaaaaawu","aaaaaaaaaaaaaawv","aaaaaaaaaaaaaaww","aaaaaaaaaaaaaawx","aaaaaaaaaaaaaawy","aaaaaaaaaaaaaawz","aaaaaaaaaaaaaaxa","aaaaaaaaaaaaaaxb","aaaaaaaaaaaaaaxc","aaaaaaaaaaaaaaxd","aaaaaaaaaaaaaaxe","aaaaaaaaaaaaaaxf","aaaaaaaaaaaaaaxg","aaaaaaaaaaaaaaxh","aaaaaaaaaaaaaaxi","aaaaaaaaaaaaaaxj","aaaaaaaaaaaaaaxk","aaaaaaaaaaaaaaxl","aaaaaaaaaaaaaaxm","aaaaaaaaaaaaaaxn","aaaaaaaaaaaaaaxo","aaaaaaaaaaaaaaxp","aaaaaaaaaaaaaaxq","aaaaaaaaaaaaaaxr","aaaaaaaaaaaaaaxs","aaaaaaaaaaaaaaxt","aaaaaaaaaaaaaaxu","aaaaaaaaaaaaaaxv","aaaaaaaaaaaaaaxw","aaaaaaaaaaaaaaxx","aaaaaaaaaaaaaaxy","aaaaaaaaaaaaaaxz","aaaaaaaaaaaaaaya","aaaaaaaaaaaaaayb","aaaaaaaaaaaaaayc","aaaaaaaaaaaaaayd","aaaaaaaaaaaaaaye","aaaaaaaaaaaaaayf","aaaaaaaaaaaaaayg","aaaaaaaaaaaaaayh","aaaaaaaaaaaaaayi","aaaaaaaaaaaaaayj","aaaaaaaaaaaaaayk","aaaaaaaaaaaaaayl","aaaaaaaaaaaaaaym","aaaaaaaaaaaaaayn","aaaaaaaaaaaaaayo","aaaaaaaaaaaaaayp","aaaaaaaaaaaaaayq","aaaaaaaaaaaaaayr","aaaaaaaaaaaaaays","aaaaaaaaaaaaaayt","aaaaaaaaaaaaaayu","aaaaaaaaaaaaaayv","aaaaaaaaaaaaaayw","aaaaaaaaaaaaaayx","aaaaaaaaaaaaaayy","aaaaaaaaaaaaaayz","aaaaaaaaaaaaaaza","aaaaaaaaaaaaaazb","aaaaaaaaaaaaaazc","aaaaaaaaaaaaaazd","aaaaaaaaaaaaaaze","aaaaaaaaaaaaaazf","aaaaaaaaaaaaaazg","aaaaaaaaaaaaaazh","aaaaaaaaaaaaaazi","aaaaaaaaaaaaaazj","aaaaaaaaaaaaaazk","aaaaaaaaaaaaaazl","aaaaaaaaaaaaaazm","aaaaaaaaaaaaaazn","aaaaaaaaaaaaaazo","aaaaaaaaaaaaaazp","aaaaaaaaaaaaaazq","aaaaaaaaaaaaaazr","aaaaaaaaaaaaaazs","aaaaaaaaaaaaaazt","aaaaaaaaaaaaaazu","aaaaaaaaaaaaaazv","aaaaaaaaaaaaaazw","aaaaaaaaaaaaaazx","aaaaaaaaaaaaaazy","aaaaaaaaaaaaaazz"])) -print(Solution().findWords([['o','a','a','n'],['e','t','a','e'],['i','h','k','r'],['i','f','l','v']],["oath","pea","eat","rain"])) -print(Solution().findWords([['a']], [])) \ No newline at end of file From 6178648ead3a4fca55b177bb41ac4a1180c002fb Mon Sep 17 00:00:00 2001 From: Nurettin <46221949+na-vural@users.noreply.github.com> Date: Thu, 29 Oct 2020 14:32:23 +0300 Subject: [PATCH 133/161] Create 0891_Sum_of_Subsequence_Widths.py --- LeetCode/0891_Sum_of_Subsequence_Widths.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 LeetCode/0891_Sum_of_Subsequence_Widths.py diff --git a/LeetCode/0891_Sum_of_Subsequence_Widths.py b/LeetCode/0891_Sum_of_Subsequence_Widths.py new file mode 100644 index 0000000..f355b2e --- /dev/null +++ b/LeetCode/0891_Sum_of_Subsequence_Widths.py @@ -0,0 +1,10 @@ +class Solution(object): + def sumSubseqWidths(self, A: List[int]) -> int: + ret_int = 0 + A_len = len(A) + A.sort(key=lambda x: int(x), reverse=True) + + for x in range(A_len): + ret_int += A[x] * (2**(A_len - x - 1) - 2**(x)) + + return ret_int % (10**9 + 7) From c58635ac8ce5461bd94c10ea8a7aa5f1220b215c Mon Sep 17 00:00:00 2001 From: Nurettin <46221949+na-vural@users.noreply.github.com> Date: Thu, 29 Oct 2020 14:36:30 +0300 Subject: [PATCH 134/161] Create 0273_Integer_to_English_Words.py --- LeetCode/0273_Integer_to_English_Words.py | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 LeetCode/0273_Integer_to_English_Words.py diff --git a/LeetCode/0273_Integer_to_English_Words.py b/LeetCode/0273_Integer_to_English_Words.py new file mode 100644 index 0000000..12a4a71 --- /dev/null +++ b/LeetCode/0273_Integer_to_English_Words.py @@ -0,0 +1,68 @@ +class Solution(object): + def numberToWords(self, num: int) -> str: + def decode(triple_str): + final_list = [] + + numbers = { "1": "One", + "2": "Two", + "3": "Three", + "4": "Four", + "5": "Five", + "6": "Six", + "7": "Seven", + "8": "Eight", + "9": "Nine", + "10": "Ten", + "11": "Eleven", + "12": "Twelve", + "13": "Thirteen", + "14": "Fourteen", + "15": "Fifteen", + "16": "Sixteen", + "17": "Seventeen", + "18": "Eighteen", + "19": "Nineteen"} + + tens = { "2": "Twenty", + "3": "Thirty", + "4": "Forty", + "5": "Fifty", + "6": "Sixty", + "7": "Seventy", + "8": "Eighty", + "9": "Ninety"} + + if int(triple_str[0]) != 0: + final_list.append("{} Hundred".format(numbers[triple_str[0]])) + if int(triple_str[1]) == 1: + final_list.append("{}".format(numbers[triple_str[1:3]])) + else: + if int(triple_str[1]) != 0: + final_list.append("{}".format(tens[triple_str[1]])) + if int(triple_str[2]) != 0: + final_list.append("{}".format(numbers[triple_str[2]])) + + return final_list + + + num_str = "{:0>12}".format(str(num)) + num_list = [] + final_num = "" + digit_dict = { 0: "Billion", + 3: "Million", + 6: "Thousand"} + + for x in range(0, 12, 3): + the_triple = num_str[x:x+3] + if the_triple == "000": + continue + else: + num_list.extend(decode(the_triple)) + if x == 9: break + num_list.append(digit_dict[x]) + + final_num = " ".join(num_list) + if final_num == "": + final_num = "Zero" + + return final_num From ecc1f01430461ccfbcef5766cd820ed005458b6b Mon Sep 17 00:00:00 2001 From: suman151 Date: Thu, 29 Oct 2020 17:10:30 +0530 Subject: [PATCH 135/161] Added path with maximum gold solution --- LeetCode/1219_path_with_maximum_gold.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 LeetCode/1219_path_with_maximum_gold.py diff --git a/LeetCode/1219_path_with_maximum_gold.py b/LeetCode/1219_path_with_maximum_gold.py new file mode 100644 index 0000000..7b76fff --- /dev/null +++ b/LeetCode/1219_path_with_maximum_gold.py @@ -0,0 +1,24 @@ +class Solution: + def getMaximumGold(self, grid: List[List[int]]) -> int: + def bfs(i,j): + stack = [(grid[i][j],i,j,set([(i,j)]))] + while stack: + temp = [] + for cur,i,j,p in stack: + if cur > self.res: + self.res = cur + self.best_res = p + for x, y in [[i+1,j], [i-1,j], [i,j+1], [i,j-1]]: + if 0<=x Date: Thu, 29 Oct 2020 17:10:41 +0530 Subject: [PATCH 136/161] Added solution for Problem 0401 Binary Watch --- .vscode/settings.json | 3 ++ LeetCode/0401_Binary_Watch.py | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 LeetCode/0401_Binary_Watch.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..25c729f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/bin/python3" +} \ No newline at end of file diff --git a/LeetCode/0401_Binary_Watch.py b/LeetCode/0401_Binary_Watch.py new file mode 100644 index 0000000..2b9f099 --- /dev/null +++ b/LeetCode/0401_Binary_Watch.py @@ -0,0 +1,69 @@ +class Solution(object): + def combination(self, n, k, inp, res): + # inp is expected to be a list of size n + #print n,k,inp,res + if k == 0: + res.append([i for i in inp]) + return + if k > n: + return + #for i in range(1,n+1): + inp[n-1] = 1 + self.combination(n-1,k-1, inp, res) + inp[n-1] = 0 + self.combination(n-1, k, inp, res) + + + def getHours(self, h): + if h == 0: + return ["0"] + if h == 1: + return ["1", "2", "4", "8"] + if h == 2: + return ["3", "5", "6", "9", "10"] + if h == 3: + return ["7", "11"] + + def getMinutes(self, m): + inp = [0,0,0,0,0,0] + res = [] + self.combination(6, m, inp, res) + mins = [1, 2, 4, 8, 16, 32] + minutes = [] + for comb in res: + i = 0 + mn = 0 + while i < 6: + if comb[i] == 1: + mn += mins[i] + i += 1 + if mn > 59: + continue + if mn < 10: + minutes.append("0" + str(mn)) + else: + minutes.append(str(mn)) + return minutes + + def readBinaryWatch(self, num): + """ + :type num: int + :rtype: List[str] + """ + i = 0 + res = [] + + while i <= num: + h = i + m = num - i + if h < 4 and m < 6: + lh = self.getHours(h) + #print lh + lm = self.getMinutes(m) + #print lm + for hr in lh: + for mn in lm: + res.append(hr + ":" + mn) + i += 1 + + return res From 5639c2a7681ad04076efc5013d539a2390c498e1 Mon Sep 17 00:00:00 2001 From: flick-23 Date: Thu, 29 Oct 2020 17:13:59 +0530 Subject: [PATCH 137/161] Added solution for Problem 0401 Binary Watch --- LeetCode/{0401_Binary_Watch.py => 0401_Binary_Watch_.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LeetCode/{0401_Binary_Watch.py => 0401_Binary_Watch_.py} (100%) diff --git a/LeetCode/0401_Binary_Watch.py b/LeetCode/0401_Binary_Watch_.py similarity index 100% rename from LeetCode/0401_Binary_Watch.py rename to LeetCode/0401_Binary_Watch_.py From 7f99033a3130b9b337c675af5cd9b1862051b709 Mon Sep 17 00:00:00 2001 From: suman151 Date: Thu, 29 Oct 2020 17:25:06 +0530 Subject: [PATCH 138/161] Added path with maximum gold solution --- LeetCode/1219_path_with_maximum_gold.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/LeetCode/1219_path_with_maximum_gold.py b/LeetCode/1219_path_with_maximum_gold.py index 7b76fff..d8d1e5d 100644 --- a/LeetCode/1219_path_with_maximum_gold.py +++ b/LeetCode/1219_path_with_maximum_gold.py @@ -1,24 +1,22 @@ class Solution: - def getMaximumGold(self, grid: List[List[int]]) -> int: - def bfs(i,j): - stack = [(grid[i][j],i,j,set([(i,j)]))] + def getMaximumGold(self, grid): + def bfs(i, j): + stack = [(grid[i][j], i, j, set([(i, j)]))] while stack: temp = [] - for cur,i,j,p in stack: + for cur, i, j, p in stack: if cur > self.res: self.res = cur self.best_res = p - for x, y in [[i+1,j], [i-1,j], [i,j+1], [i,j-1]]: - if 0<=x Date: Thu, 29 Oct 2020 17:31:47 +0530 Subject: [PATCH 139/161] Added solution for Problem 0209 Minimum Subarray Sum --- LeetCode/0209_ Minimum_Size_Subarray_Sum_.py | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LeetCode/0209_ Minimum_Size_Subarray_Sum_.py diff --git a/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py b/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py new file mode 100644 index 0000000..bd17997 --- /dev/null +++ b/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py @@ -0,0 +1,55 @@ +class Solution: + def minSubArrayLen(self, s, nums): + """ + :type s: int + :type nums: List[int] + :rtype: int + """ + + # approach: + # 1. build a prefix list and iterate it + # 2. at each iteration, use binary search to find prefix+s + # 3. after search done, get length between left and i + + n = len(nums) + result = n + 1 + + if n == 0: + return 0 + + # build prefix sums array + prefix = [0 for i in range(n+1)] + for i in range(1, n+1): + prefix[i] = prefix[i-1] + nums[i-1] + + # for each iteration i, we try to use binary search to find + # prefix[i] + s, which means the sum of subarray between i + # and left will be more than s + for i in range(n): + left = i + 1 + right = n + target = prefix[i] + s + + while left <= right: + m = left + (right - left) // 2 + + if prefix[m] < target: + left = m + 1 + + # in both greater and equal cases, we have to update + # right index for finding the leftist sum which is + # larger than target + else: + right = m - 1 + + # end for-loop immediately if left is greater than n because + # it means every sum will be less than targer in following iteration + if left > n: + break + + # if left is valid, left will be the leftist element that is + # larger than target, so length between left and i is what we need + if left - i < result: + result = left - i + + return 0 if result > n else result \ No newline at end of file From 1f6384d1902d6d01d3b7ee6cdd6a531b7d248d4b Mon Sep 17 00:00:00 2001 From: flick-23 Date: Thu, 29 Oct 2020 17:38:32 +0530 Subject: [PATCH 140/161] Added solution for Problem 0209 Minimum Subarray Sum --- LeetCode/0209_ Minimum_Size_Subarray_Sum_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py b/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py index bd17997..0917675 100644 --- a/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py +++ b/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py @@ -10,7 +10,7 @@ def minSubArrayLen(self, s, nums): # 1. build a prefix list and iterate it # 2. at each iteration, use binary search to find prefix+s # 3. after search done, get length between left and i - + n = len(nums) result = n + 1 From cc5d6cf192f97ed6b21bbb3b571f61c8b8a970cf Mon Sep 17 00:00:00 2001 From: Venkatesh Dhongadi <51364640+flick-23@users.noreply.github.com> Date: Thu, 29 Oct 2020 18:00:59 +0530 Subject: [PATCH 141/161] Delete 0209_ Minimum_Size_Subarray_Sum_.py --- LeetCode/0209_ Minimum_Size_Subarray_Sum_.py | 55 -------------------- 1 file changed, 55 deletions(-) delete mode 100644 LeetCode/0209_ Minimum_Size_Subarray_Sum_.py diff --git a/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py b/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py deleted file mode 100644 index 0917675..0000000 --- a/LeetCode/0209_ Minimum_Size_Subarray_Sum_.py +++ /dev/null @@ -1,55 +0,0 @@ -class Solution: - def minSubArrayLen(self, s, nums): - """ - :type s: int - :type nums: List[int] - :rtype: int - """ - - # approach: - # 1. build a prefix list and iterate it - # 2. at each iteration, use binary search to find prefix+s - # 3. after search done, get length between left and i - - n = len(nums) - result = n + 1 - - if n == 0: - return 0 - - # build prefix sums array - prefix = [0 for i in range(n+1)] - for i in range(1, n+1): - prefix[i] = prefix[i-1] + nums[i-1] - - # for each iteration i, we try to use binary search to find - # prefix[i] + s, which means the sum of subarray between i - # and left will be more than s - for i in range(n): - left = i + 1 - right = n - target = prefix[i] + s - - while left <= right: - m = left + (right - left) // 2 - - if prefix[m] < target: - left = m + 1 - - # in both greater and equal cases, we have to update - # right index for finding the leftist sum which is - # larger than target - else: - right = m - 1 - - # end for-loop immediately if left is greater than n because - # it means every sum will be less than targer in following iteration - if left > n: - break - - # if left is valid, left will be the leftist element that is - # larger than target, so length between left and i is what we need - if left - i < result: - result = left - i - - return 0 if result > n else result \ No newline at end of file From 4ed65a287d3b2d8b12f219240a894e62422f6b2d Mon Sep 17 00:00:00 2001 From: flick-23 Date: Thu, 29 Oct 2020 18:02:55 +0530 Subject: [PATCH 142/161] Added solution for Problem 0209 Minimum Size Sub Array Sum --- 0209_Minimum_Size_Subarray_Sum_.py | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 0209_Minimum_Size_Subarray_Sum_.py diff --git a/0209_Minimum_Size_Subarray_Sum_.py b/0209_Minimum_Size_Subarray_Sum_.py new file mode 100644 index 0000000..0917675 --- /dev/null +++ b/0209_Minimum_Size_Subarray_Sum_.py @@ -0,0 +1,55 @@ +class Solution: + def minSubArrayLen(self, s, nums): + """ + :type s: int + :type nums: List[int] + :rtype: int + """ + + # approach: + # 1. build a prefix list and iterate it + # 2. at each iteration, use binary search to find prefix+s + # 3. after search done, get length between left and i + + n = len(nums) + result = n + 1 + + if n == 0: + return 0 + + # build prefix sums array + prefix = [0 for i in range(n+1)] + for i in range(1, n+1): + prefix[i] = prefix[i-1] + nums[i-1] + + # for each iteration i, we try to use binary search to find + # prefix[i] + s, which means the sum of subarray between i + # and left will be more than s + for i in range(n): + left = i + 1 + right = n + target = prefix[i] + s + + while left <= right: + m = left + (right - left) // 2 + + if prefix[m] < target: + left = m + 1 + + # in both greater and equal cases, we have to update + # right index for finding the leftist sum which is + # larger than target + else: + right = m - 1 + + # end for-loop immediately if left is greater than n because + # it means every sum will be less than targer in following iteration + if left > n: + break + + # if left is valid, left will be the leftist element that is + # larger than target, so length between left and i is what we need + if left - i < result: + result = left - i + + return 0 if result > n else result \ No newline at end of file From 8d2a8a313b32bdf06e1de34c9ecb3ea466ad9498 Mon Sep 17 00:00:00 2001 From: Venkatesh Dhongadi <51364640+flick-23@users.noreply.github.com> Date: Thu, 29 Oct 2020 18:06:42 +0530 Subject: [PATCH 143/161] Delete 0209_Minimum_Size_Subarray_Sum_.py --- 0209_Minimum_Size_Subarray_Sum_.py | 55 ------------------------------ 1 file changed, 55 deletions(-) delete mode 100644 0209_Minimum_Size_Subarray_Sum_.py diff --git a/0209_Minimum_Size_Subarray_Sum_.py b/0209_Minimum_Size_Subarray_Sum_.py deleted file mode 100644 index 0917675..0000000 --- a/0209_Minimum_Size_Subarray_Sum_.py +++ /dev/null @@ -1,55 +0,0 @@ -class Solution: - def minSubArrayLen(self, s, nums): - """ - :type s: int - :type nums: List[int] - :rtype: int - """ - - # approach: - # 1. build a prefix list and iterate it - # 2. at each iteration, use binary search to find prefix+s - # 3. after search done, get length between left and i - - n = len(nums) - result = n + 1 - - if n == 0: - return 0 - - # build prefix sums array - prefix = [0 for i in range(n+1)] - for i in range(1, n+1): - prefix[i] = prefix[i-1] + nums[i-1] - - # for each iteration i, we try to use binary search to find - # prefix[i] + s, which means the sum of subarray between i - # and left will be more than s - for i in range(n): - left = i + 1 - right = n - target = prefix[i] + s - - while left <= right: - m = left + (right - left) // 2 - - if prefix[m] < target: - left = m + 1 - - # in both greater and equal cases, we have to update - # right index for finding the leftist sum which is - # larger than target - else: - right = m - 1 - - # end for-loop immediately if left is greater than n because - # it means every sum will be less than targer in following iteration - if left > n: - break - - # if left is valid, left will be the leftist element that is - # larger than target, so length between left and i is what we need - if left - i < result: - result = left - i - - return 0 if result > n else result \ No newline at end of file From 99861bc23be4bb1ba6c6e0384319a9e594d827c5 Mon Sep 17 00:00:00 2001 From: UdeshAthukorala Date: Thu, 29 Oct 2020 19:33:25 +0530 Subject: [PATCH 144/161] Add 0084_Largest_Rectangle_in_Histogram.py --- LeetCode/0084_Largest_Rectangle_in_Histogram.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 LeetCode/0084_Largest_Rectangle_in_Histogram.py diff --git a/LeetCode/0084_Largest_Rectangle_in_Histogram.py b/LeetCode/0084_Largest_Rectangle_in_Histogram.py new file mode 100644 index 0000000..8e1b7e0 --- /dev/null +++ b/LeetCode/0084_Largest_Rectangle_in_Histogram.py @@ -0,0 +1,15 @@ +class Solution: + def largestRectangleArea(self, heights: List[int]) -> int: + heights.append(0) + lst = [-1] + output = 0 + + for i in range(len(heights)): + while (heights[i] < heights[lst[-1]]): + height = heights[lst.pop()] + width = i - lst[-1] - 1 + output = max(output, height * width) + lst.append(i) + + heights.pop() + return output From 833fb6dd3e0455d316290347e2166dbbff7fb6b4 Mon Sep 17 00:00:00 2001 From: Soroosh Date: Thu, 29 Oct 2020 20:22:49 +0100 Subject: [PATCH 145/161] Solution added passing leetcode test --- LeetCode/0371_sum_of_two_integers.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/0371_sum_of_two_integers.py diff --git a/LeetCode/0371_sum_of_two_integers.py b/LeetCode/0371_sum_of_two_integers.py new file mode 100644 index 0000000..5f01711 --- /dev/null +++ b/LeetCode/0371_sum_of_two_integers.py @@ -0,0 +1,13 @@ +class Solution: + def getSum(self, a: int, b: int) -> int: + # 32 bits integer max and min + MAX = 0x7FFFFFFF + MIN = 0x80000000 + + mask = 0xFFFFFFFF + + while b != 0: + carry = a & b + a, b = (a ^ b) & mask, (carry << 1) & mask + + return a if a <= MAX else ~(a ^ mask) \ No newline at end of file From 8f27130d92fd1e9428477c30ae65b6fa85ac2aa3 Mon Sep 17 00:00:00 2001 From: Achyut-sudo <71660666+Achyut-sudo@users.noreply.github.com> Date: Fri, 30 Oct 2020 01:59:19 +0530 Subject: [PATCH 146/161] uploaded code --- ...bstring_with_Concatenation_of_All_Words.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 LeetCode/0030_Substring_with_Concatenation_of_All_Words.py diff --git a/LeetCode/0030_Substring_with_Concatenation_of_All_Words.py b/LeetCode/0030_Substring_with_Concatenation_of_All_Words.py new file mode 100644 index 0000000..5ca0881 --- /dev/null +++ b/LeetCode/0030_Substring_with_Concatenation_of_All_Words.py @@ -0,0 +1,26 @@ +class Solution: + + def findSubstring(self,s, words): + self.Incr = len(words[0]) + self.LenWords = len(words) + self.Index = 0 + self.m = self.Incr * self.LenWords + self.Max = len(s) - self.m + self.output = [] + while self.Index <= self.Max : + WordsCopy = words.copy() + upperBound = self.Index + lowerBound = upperBound + self.m + for i in range(upperBound,lowerBound,self.Incr): + tempStr = s[i: i + self.Incr] + if tempStr in WordsCopy : + WordsCopy.remove(tempStr) + else: + break + if WordsCopy == [] : + self.output.append(self.Index) + self.Index += 1 + return self.output + + + \ No newline at end of file From afc5b6f4d0eaa49238b96ed9b758e6ae103a2e0c Mon Sep 17 00:00:00 2001 From: Sounakde Date: Fri, 30 Oct 2020 14:15:32 +0530 Subject: [PATCH 147/161] adding 0389_FindThe Difference solution for merging --- LeetCode/0389_FindTheDifference.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 LeetCode/0389_FindTheDifference.py diff --git a/LeetCode/0389_FindTheDifference.py b/LeetCode/0389_FindTheDifference.py new file mode 100644 index 0000000..06c2265 --- /dev/null +++ b/LeetCode/0389_FindTheDifference.py @@ -0,0 +1,30 @@ +import sys +import random + +# The function which will do the main operation of finding the difference + +class Solution: + def FindTheDifference(self, s: str, t: str) -> str: + for char in s: + if 96 <= ord(char) <= 123: + if 0 < len(s) < 1000: + if len(t) == len(s) + 1: + extra_char = t[-1] + return extra_char + else: + print("Differnce between second and first string is more than 1") + if s == '': + if 0 <= len(s) <= 1000: + if len(t) == len(s) + 1: + extra_char = t[-1] + return extra_char + else: + print("Differnce between second and first string is more than 1") + +if __name__ == "__main__": + # Initialising the string variable with input from the user + s = sys.argv[1] + # Initialising the second string variable with input from user + t = sys.argv[2] + solution = Solution().FindTheDifference(s, t) + print(solution) \ No newline at end of file From e3cf5dff48bec066be1ff8bfcf3c4b031f3b898a Mon Sep 17 00:00:00 2001 From: Achyut-sudo <71660666+Achyut-sudo@users.noreply.github.com> Date: Fri, 30 Oct 2020 21:14:40 +0530 Subject: [PATCH 148/161] Uploaded code --- LeetCode/0289_Game_of_Life.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 LeetCode/0289_Game_of_Life.py diff --git a/LeetCode/0289_Game_of_Life.py b/LeetCode/0289_Game_of_Life.py new file mode 100644 index 0000000..a312714 --- /dev/null +++ b/LeetCode/0289_Game_of_Life.py @@ -0,0 +1,42 @@ +class Solution: + def gameOfLife(self, board): + self.m = len(board) + self.n = len(board[0]) + self.board = [rows.copy() for rows in board] + for i in range(self.m): + for j in range(self.n): + state = self.board[i][j] + dataDict = self.CheckNeighbors(i,j) + nextGen = self.NextGenState(state,dataDict) + board[i][j] = nextGen + + + def CheckNeighbors(self,row,column): + retDict = {"live":0,"dead":0} + lb = max(column-1,0) + rb = min(column+2,self.n) + tb = max(row -1,0) + bb = min(row+2,self.m) + for rows in range(tb,bb): + for columns in range(lb,rb): + if rows != row or columns != column : + neighbor = self.board[rows][columns] + if neighbor == 1: + retDict["live"] += 1 + else: + retDict["dead"] += 1 + return retDict + + def NextGenState(self,state,dataDict): + finalState = 0 + liveNeighbors = dataDict["live"] + if state == 1: + if liveNeighbors == 2 or liveNeighbors == 3: + finalState = 1 + else: + if liveNeighbors == 3: + finalState = 1 + return finalState + + + From 9f7896659ed72ca3d3bab4f577dfcae2aff0c174 Mon Sep 17 00:00:00 2001 From: Biraj De Date: Fri, 30 Oct 2020 23:59:56 +0530 Subject: [PATCH 149/161] Added 1550_Three_Consecutive_Odds.py --- LeetCode/1550_Three_Consecutive_Odds.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 LeetCode/1550_Three_Consecutive_Odds.py diff --git a/LeetCode/1550_Three_Consecutive_Odds.py b/LeetCode/1550_Three_Consecutive_Odds.py new file mode 100644 index 0000000..cc99bea --- /dev/null +++ b/LeetCode/1550_Three_Consecutive_Odds.py @@ -0,0 +1,3 @@ +class Solution: + def threeConsecutiveOdds(self, arr: List[int]) -> bool: + return '111' in "".join([str(i%2) for i in arr]) \ No newline at end of file From 72f8973c98ccb66b0d4c3688f021b8e091fe20e5 Mon Sep 17 00:00:00 2001 From: Bar Rotstein Date: Sat, 31 Oct 2020 11:42:36 +0200 Subject: [PATCH 150/161] added a buddy strings implementation --- LeetCode/0859_Buddy_String.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LeetCode/0859_Buddy_String.py diff --git a/LeetCode/0859_Buddy_String.py b/LeetCode/0859_Buddy_String.py new file mode 100644 index 0000000..fdcec92 --- /dev/null +++ b/LeetCode/0859_Buddy_String.py @@ -0,0 +1,13 @@ +class Solution: + def buddyStrings(self, A: str, B: str) -> bool: + indexes_to_swap = [] + for idx, string in enumerate(A): + if string != B[idx]: + indexes_to_swap.append(idx) + if len(indexes_to_swap) > 2: + return False + + if len(indexes_to_swap) != 2: + return false + + return A[indexes_to_swap[0]] == B[indexes_to_swap[1]] and A[indexes_to_swap[1]] == B[indexes_to_swap[0]] From 1c40079195ffe5f055e098dc12c20a65b7d3fbd6 Mon Sep 17 00:00:00 2001 From: barrotsteindev Date: Sat, 31 Oct 2020 12:06:35 +0200 Subject: [PATCH 151/161] pass all LeetCode tests --- LeetCode/0859_Buddy_String.py | 44 ++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/LeetCode/0859_Buddy_String.py b/LeetCode/0859_Buddy_String.py index fdcec92..69f4602 100644 --- a/LeetCode/0859_Buddy_String.py +++ b/LeetCode/0859_Buddy_String.py @@ -1,13 +1,31 @@ -class Solution: - def buddyStrings(self, A: str, B: str) -> bool: - indexes_to_swap = [] - for idx, string in enumerate(A): - if string != B[idx]: - indexes_to_swap.append(idx) - if len(indexes_to_swap) > 2: - return False - - if len(indexes_to_swap) != 2: - return false - - return A[indexes_to_swap[0]] == B[indexes_to_swap[1]] and A[indexes_to_swap[1]] == B[indexes_to_swap[0]] +class Solution: + @staticmethod + def update_char_count(char, char_count): + curr_char_count = char_count.get(char, 0) + curr_char_count += 1 + char_count[char] = curr_char_count + + + def buddyStrings(self, A: str, B: str) -> bool: + char_count = {} + indexes_to_swap = [] + dup = False + for idx, string in enumerate(A): + curr_char_count = char_count.get(string, 0) + curr_char_count += 1 + char_count[string] = curr_char_count + if (curr_char_count > 1): + dup = True + if string != B[idx]: + indexes_to_swap.append(idx) + if len(indexes_to_swap) > 2: + return False + + if len(indexes_to_swap) == 1: + return False + + if len(indexes_to_swap) == 2: + return A[indexes_to_swap[0]] == B[indexes_to_swap[1]] and A[indexes_to_swap[1]] == B[indexes_to_swap[0]] + return dup + +print(Solution().buddyStrings("aa", "aa")) From fdf2ed0cb42d979e2d83ef1a8c61bfc4c77b98b0 Mon Sep 17 00:00:00 2001 From: barrotsteindev Date: Sat, 31 Oct 2020 12:09:09 +0200 Subject: [PATCH 152/161] removed unused code --- LeetCode/0859_Buddy_String.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/LeetCode/0859_Buddy_String.py b/LeetCode/0859_Buddy_String.py index 69f4602..ddd3014 100644 --- a/LeetCode/0859_Buddy_String.py +++ b/LeetCode/0859_Buddy_String.py @@ -1,12 +1,7 @@ class Solution: - @staticmethod - def update_char_count(char, char_count): - curr_char_count = char_count.get(char, 0) - curr_char_count += 1 - char_count[char] = curr_char_count - - - def buddyStrings(self, A: str, B: str) -> bool: + def buddyStrings(self, A: str, B: str) -> bool: + if len(A) != len(B): + return False char_count = {} indexes_to_swap = [] dup = False From d1e334ce19f10e77859511a986fea30d018b3a46 Mon Sep 17 00:00:00 2001 From: barrotsteindev Date: Sat, 31 Oct 2020 12:09:34 +0200 Subject: [PATCH 153/161] removed print() --- LeetCode/0859_Buddy_String.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/LeetCode/0859_Buddy_String.py b/LeetCode/0859_Buddy_String.py index ddd3014..55695c9 100644 --- a/LeetCode/0859_Buddy_String.py +++ b/LeetCode/0859_Buddy_String.py @@ -22,5 +22,3 @@ def buddyStrings(self, A: str, B: str) -> bool: if len(indexes_to_swap) == 2: return A[indexes_to_swap[0]] == B[indexes_to_swap[1]] and A[indexes_to_swap[1]] == B[indexes_to_swap[0]] return dup - -print(Solution().buddyStrings("aa", "aa")) From ded0eff51ec486b22c442ace5793c6d68006ffcc Mon Sep 17 00:00:00 2001 From: Sounakde Date: Sat, 31 Oct 2020 15:44:07 +0530 Subject: [PATCH 154/161] adding 0389_FindTheDifference solution for merging with corresponding issue --- LeetCode/0389_FindTheDifference.py | 40 +++++++++++------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/LeetCode/0389_FindTheDifference.py b/LeetCode/0389_FindTheDifference.py index 06c2265..7495dcf 100644 --- a/LeetCode/0389_FindTheDifference.py +++ b/LeetCode/0389_FindTheDifference.py @@ -1,30 +1,20 @@ import sys -import random - -# The function which will do the main operation of finding the difference class Solution: def FindTheDifference(self, s: str, t: str) -> str: - for char in s: - if 96 <= ord(char) <= 123: - if 0 < len(s) < 1000: - if len(t) == len(s) + 1: - extra_char = t[-1] - return extra_char - else: - print("Differnce between second and first string is more than 1") - if s == '': - if 0 <= len(s) <= 1000: - if len(t) == len(s) + 1: - extra_char = t[-1] - return extra_char - else: - print("Differnce between second and first string is more than 1") + a = 0 + b = 0 + if 0 <= len(s) <= 1000: + for chars in s: + if 97 <= ord(chars) <= 122: + a += ord(chars) + for letters in t: + if 97 <= ord(letters) <= 122: + b += ord(letters) + return chr(b - a) + -if __name__ == "__main__": - # Initialising the string variable with input from the user - s = sys.argv[1] - # Initialising the second string variable with input from user - t = sys.argv[2] - solution = Solution().FindTheDifference(s, t) - print(solution) \ No newline at end of file +s = sys.argv[1] +t = sys.argv[2] +solution = Solution().FindTheDifference(s,t) +print(solution) \ No newline at end of file From f74d5624d8adba23b943a0fdc7d304bd7a39c5d6 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Sat, 31 Oct 2020 19:23:50 +0100 Subject: [PATCH 155/161] Delete settings.json --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 25c729f..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/bin/python3" -} \ No newline at end of file From 8a66d3bfbaeda24b360f54dda00b41bbe10a57b6 Mon Sep 17 00:00:00 2001 From: chw9 <43727884+chw9@users.noreply.github.com> Date: Sat, 31 Oct 2020 15:06:28 -0400 Subject: [PATCH 156/161] added solution to 0599 --- .../0599_Minimum_Index_Sum_of_Two_Lists.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LeetCode/0599_Minimum_Index_Sum_of_Two_Lists.py diff --git a/LeetCode/0599_Minimum_Index_Sum_of_Two_Lists.py b/LeetCode/0599_Minimum_Index_Sum_of_Two_Lists.py new file mode 100644 index 0000000..d43ce31 --- /dev/null +++ b/LeetCode/0599_Minimum_Index_Sum_of_Two_Lists.py @@ -0,0 +1,20 @@ +class Solution(object): + def findRestaurant(self, list1, list2): + ind1 = 0 + ind2 = 0 + ind_sum = sys.maxsize + rest = list() + + for restaurant1 in list1: + for restaurant2 in list2: + if (restaurant1 == restaurant2) and ((ind1 + ind2) < ind_sum): + ind_sum = ind1 + ind2 + rest = [] + rest.append(restaurant2) + elif (restaurant1 == restaurant2) and ((ind1 + ind2) == ind_sum): + rest.append(restaurant2) + ind2 = ind2 + 1 + ind1 = ind1 + 1 + ind2 = 0 + + return rest \ No newline at end of file From eabee1b0320242e977f1d65b7bb2459e75d87d91 Mon Sep 17 00:00:00 2001 From: Sounakde <65114561+Sounakde@users.noreply.github.com> Date: Sun, 1 Nov 2020 09:59:42 +0530 Subject: [PATCH 157/161] Update 0389_FindTheDifference.py I have edited the file and checked the solution in LeetCode website a 2nd time. The solution is being accepted by the website now. --- LeetCode/0389_FindTheDifference.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/LeetCode/0389_FindTheDifference.py b/LeetCode/0389_FindTheDifference.py index 7495dcf..0da6419 100644 --- a/LeetCode/0389_FindTheDifference.py +++ b/LeetCode/0389_FindTheDifference.py @@ -1,7 +1,5 @@ -import sys - class Solution: - def FindTheDifference(self, s: str, t: str) -> str: + def findTheDifference(self, s: str, t: str) -> str: a = 0 b = 0 if 0 <= len(s) <= 1000: @@ -12,9 +10,3 @@ def FindTheDifference(self, s: str, t: str) -> str: if 97 <= ord(letters) <= 122: b += ord(letters) return chr(b - a) - - -s = sys.argv[1] -t = sys.argv[2] -solution = Solution().FindTheDifference(s,t) -print(solution) \ No newline at end of file From dc3323840e9d8121c596338273ce96e958fd541f Mon Sep 17 00:00:00 2001 From: flick-23 Date: Sun, 1 Nov 2020 13:36:22 +0530 Subject: [PATCH 158/161] Added Solution to Problem 0234 Palindrome Linked List --- LeetCode/0234_Palindrome_Linked_List_.py | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 LeetCode/0234_Palindrome_Linked_List_.py diff --git a/LeetCode/0234_Palindrome_Linked_List_.py b/LeetCode/0234_Palindrome_Linked_List_.py new file mode 100644 index 0000000..2522fc7 --- /dev/null +++ b/LeetCode/0234_Palindrome_Linked_List_.py @@ -0,0 +1,42 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + + def reverse(self, head): + p = head.next + while p and p.next: + tmp = p.next + p.next = p.next.next + tmp.next = head.next + head.next = tmp + + def isPalindrome(self, head): + """ + :type head: ListNode + :rtype: bool + """ + + #get middle pointer + p1 = ListNode(0) + p1.next = head + p2 = p1 + while p2 and p2.next: + p1 = p1.next + p2 = p2.next.next + + # reverse second half of list + self.reverse(p1) + + # check palindrome + p1 = p1.next + p2 = head + while p1: + if p1.val != p2.val: + return False + p1 = p1.next + p2 = p2.next + return True \ No newline at end of file From 8675615a41c52c6fb38532e888e97a82ebeb718e Mon Sep 17 00:00:00 2001 From: Prince Singh Tomar Date: Mon, 2 Nov 2020 02:31:06 +0530 Subject: [PATCH 159/161] added code of Questions 0052,0110 and 0145 --- LeetCode/0052_N_Queens_2.py | 13 ++++++++++++ LeetCode/0110_balanced_binary_tree.py | 21 +++++++++++++++++++ .../0145_binary_tree_postorder_traversal.py | 18 ++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 LeetCode/0052_N_Queens_2.py create mode 100644 LeetCode/0110_balanced_binary_tree.py create mode 100644 LeetCode/0145_binary_tree_postorder_traversal.py diff --git a/LeetCode/0052_N_Queens_2.py b/LeetCode/0052_N_Queens_2.py new file mode 100644 index 0000000..30b03d1 --- /dev/null +++ b/LeetCode/0052_N_Queens_2.py @@ -0,0 +1,13 @@ +class Solution(object): + # @return an integer + def totalNQueens(self, n): + return self.totalNQueensRecu([], 0, n) + + def totalNQueensRecu(self, solution, row, n): + if row == n: + return 1 + result = 0 + for i in xrange(n): + if i not in solution and reduce(lambda acc, j: abs(row - j) != abs(i - solution[j]) and acc, xrange(len(solution)), True): + result += self.totalNQueensRecu(solution + [i], row + 1, n) + return result \ No newline at end of file diff --git a/LeetCode/0110_balanced_binary_tree.py b/LeetCode/0110_balanced_binary_tree.py new file mode 100644 index 0000000..e99066c --- /dev/null +++ b/LeetCode/0110_balanced_binary_tree.py @@ -0,0 +1,21 @@ +#class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + + +class Solution(object): + # @param root, a tree node + # @return a boolean + def isBalanced(self, root): + def getHeight(root): + if root is None: + return 0 + left_height, right_height = \ + getHeight(root.left), getHeight(root.right) + if left_height < 0 or right_height < 0 or \ + abs(left_height - right_height) > 1: + return -1 + return max(left_height, right_height) + 1 + return (getHeight(root) >= 0) \ No newline at end of file diff --git a/LeetCode/0145_binary_tree_postorder_traversal.py b/LeetCode/0145_binary_tree_postorder_traversal.py new file mode 100644 index 0000000..ef7c7fc --- /dev/null +++ b/LeetCode/0145_binary_tree_postorder_traversal.py @@ -0,0 +1,18 @@ +class Solution(object): + def postorderTraversal(self, root): + """ + :type root: TreeNode + :rtype: List[int] + """ + result, stack = [], [(root, False)] + while stack: + root, is_visited = stack.pop() + if root is None: + continue + if is_visited: + result.append(root.val) + else: + stack.append((root, True)) + stack.append((root.right, False)) + stack.append((root.left, False)) + return result \ No newline at end of file From 72e0608ba0ce41229653e75f0b03ea212be8f88e Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Mon, 2 Nov 2020 00:18:37 +0100 Subject: [PATCH 160/161] Renaming Files Missing Leading Zero --- ...e_in_a_Linked_List.py => 0237_Delete_Node_in_a_Linked_List.py} | 0 ...Preorder_Traversal.py => 0589_Nary_Tree_Preorder_Traversal.py} | 0 .../{997_Find_The_Town_Judge.py => 0997_Find_The_Town_Judge.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename LeetCode/{237_Delete_Node_in_a_Linked_List.py => 0237_Delete_Node_in_a_Linked_List.py} (100%) rename LeetCode/{589_Nary_Tree_Preorder_Traversal.py => 0589_Nary_Tree_Preorder_Traversal.py} (100%) rename LeetCode/{997_Find_The_Town_Judge.py => 0997_Find_The_Town_Judge.py} (100%) diff --git a/LeetCode/237_Delete_Node_in_a_Linked_List.py b/LeetCode/0237_Delete_Node_in_a_Linked_List.py similarity index 100% rename from LeetCode/237_Delete_Node_in_a_Linked_List.py rename to LeetCode/0237_Delete_Node_in_a_Linked_List.py diff --git a/LeetCode/589_Nary_Tree_Preorder_Traversal.py b/LeetCode/0589_Nary_Tree_Preorder_Traversal.py similarity index 100% rename from LeetCode/589_Nary_Tree_Preorder_Traversal.py rename to LeetCode/0589_Nary_Tree_Preorder_Traversal.py diff --git a/LeetCode/997_Find_The_Town_Judge.py b/LeetCode/0997_Find_The_Town_Judge.py similarity index 100% rename from LeetCode/997_Find_The_Town_Judge.py rename to LeetCode/0997_Find_The_Town_Judge.py From 7256a9e3bb71d37614c8cfa7bbb6d011ac456ae3 Mon Sep 17 00:00:00 2001 From: Viktoria Jechsmayr Date: Tue, 21 Sep 2021 20:57:08 +0200 Subject: [PATCH 161/161] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46f4b1a..491214d 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,8 @@ git push origin branch-name * PRs that "correct" Typos or spam files with comments * PRs that "correct" Coding Styles - Please accept that everybody has a different style -## Hacktoberfest +## Hacktoberfest 2020 During October there come pretty much PRs and Issues - Please be patient because of my fulltime job I cannot be online 24/7 - I do my best to work through your PRs as soon as possible. +This Repository is open for **Hacktoberfest 2020 ONLY**! No PRs/Issues for Hacktoberfest 2021 or later will be accepted and marked as **invalid/spam** __Thank You!__