-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,12 @@ def evalRPN(self, tokens: List[str]) -> int: | |
| else: | ||
| y = stack.pop() | ||
| x = stack.pop() | ||
| if token == '+': stack.append(x + y) | ||
| if token == '-': stack.append(x - y) | ||
| if token == '*': stack.append(x * y) | ||
| if token == '/': stack.append(int(x / y)) | ||
| if token == '*': | ||
| stack.append(x * y) | ||
| elif token == '+': | ||
| stack.append(x + y) | ||
| elif token == '-': | ||
| stack.append(x - y) | ||
| elif token == '/': | ||
| stack.append(int(x / y)) | ||
|
Comment on lines
-15
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return stack[0] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| class Solution: | ||
| def check(self, number, nums1, nums2): | ||
| index = nums2.index(number) | ||
| for _ in range(index, len(nums2)): | ||
| if(nums2[_]>number): | ||
| return nums2[_] | ||
| return -1 | ||
| return next( | ||
| (nums2[_] for _ in range(index, len(nums2)) if (nums2[_] > number)), -1 | ||
| ) | ||
|
Comment on lines
-4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: | ||
| return [self.check(x, nums1, nums2) for x in nums1] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| class Solution: | ||
| def myPow(self, x: float, n: int) -> float: | ||
| if not n: return 1 | ||
| power = self.myPow(x, int(n/2)) | ||
| power = self.myPow(x, n // 2) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if n % 2 == 0: | ||
| return power * power | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,7 @@ def longestPalindrome(self, s: str) -> str: | |
| left,right = i,i | ||
| ls = "" | ||
| while 0<=left<size and 0<=right<size and s[left]==s[right]: | ||
| if left==right: | ||
| ls = s[left] | ||
| else: | ||
| ls = s[left] + ls + s[right] | ||
| ls = s[left] if left==right else s[left] + ls + s[right] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| left-=1 | ||
| right+=1 | ||
| #Even Palindrome | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ class Solution: | |
| def orangesRotting(self, grid: List[List[int]]) -> int: | ||
| n = len(grid) | ||
| m = len(grid[0]) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| count = 0 | ||
| rotten = [] | ||
| for i in range(n): | ||
|
|
@@ -15,13 +15,13 @@ def orangesRotting(self, grid: List[List[int]]) -> int: | |
| count+=1 | ||
| elif grid[i][j] == 1: | ||
| count+=1 | ||
|
|
||
|
|
||
| if count == 0: | ||
| return 0 | ||
|
|
||
| cycles = 0 | ||
|
|
||
| while rotten: | ||
| count-=len(rotten) | ||
| newRotten = [] | ||
|
|
@@ -32,11 +32,8 @@ def orangesRotting(self, grid: List[List[int]]) -> int: | |
| self.destroy(grid,i,j-1,n,m,newRotten) | ||
| rotten = newRotten | ||
| cycles+=1 | ||
|
|
||
| if count>0: | ||
| return -1 | ||
| else: | ||
| return cycles-1 | ||
|
|
||
| return -1 if count>0 else cycles-1 | ||
|
|
||
| def destroy(self, grid, i, j, n, m, rotten): | ||
| if 0<=i<n and 0<=j<m: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,16 +38,19 @@ | |
| -10^6 <= arr[i] <= 10^6 | ||
| """ | ||
|
|
||
| def smallestDifference(arr1 : list, arr2 : list) : | ||
| arr1.sort();arr2.sort() | ||
| i = 0;j = 0 | ||
| def smallestDifference(arr1 : list, arr2 : list): | ||
| arr1.sort() | ||
| arr2.sort() | ||
| i = 0 | ||
| j = 0 | ||
|
|
||
| smallest = float("inf") | ||
| current=float("inf") | ||
| smallestPair = [] | ||
|
|
||
| smallest = float("inf");current=float("inf") | ||
| smallestPair = list() | ||
|
|
||
| while i < len(arr1) and j < len(arr2) : | ||
| fnum = arr1[i];snum = arr2[j] | ||
|
|
||
|
Comment on lines
-41
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if fnum < snum : | ||
| current = snum - fnum | ||
| i += 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,10 +29,10 @@ | |
| Output: [] | ||
| """ | ||
|
|
||
| def sum_of_three(arr, target=0) : | ||
| result = list() | ||
| def sum_of_three(arr, target=0): | ||
| result = [] | ||
| arr.sort() | ||
|
|
||
|
Comment on lines
-32
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for i in range(len(arr)-2) : | ||
| left = i+1;right=len(arr)-1 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| def sumBase(n: int, k: int) : | ||
| def sumBase(n: int, k: int): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| """ | ||
| Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k. | ||
| After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10. | ||
|
|
@@ -9,9 +9,9 @@ def sumBase(n: int, k: int) : | |
| return value : int | ||
| """ | ||
| summation=0 | ||
| while n >= k : | ||
| while n >= k: | ||
|
|
||
| summation = summation + n%k | ||
| n=n//k | ||
| print(n) | ||
| n //= k | ||
| print(n) | ||
| return (summation + n) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,9 @@ | |
| class Solution: | ||
| def containsDuplicate(self, nums: List[int]) -> bool: | ||
| count = {} | ||
| for n in nums : | ||
| if count.get(n) != None : | ||
| for n in nums: | ||
| if count.get(n) is None: | ||
| count[n] = 1 | ||
| else: | ||
| return True | ||
| count[n] = 1 | ||
|
Comment on lines
-9
to
-12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return False | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,7 @@ def canJump(nums): | |
| while ptr2 >= 0: | ||
| if nums[ptr2] >= ptr1 - ptr2: | ||
| ptr1 = ptr2 | ||
| ptr2 -= 1 | ||
| else : | ||
| ptr2 -= 1 | ||
|
|
||
| if ptr1 == 0: | ||
| return True | ||
| else: | ||
| return False | ||
| ptr2 -= 1 | ||
| return ptr1 == 0 | ||
|
Comment on lines
-25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| print(canJump[3,2,1,0,4]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,11 @@ def longestValidParentheses(self, s): | |
| ans=0 | ||
| stack=[-1] | ||
| for i in range(len(s)): | ||
| if(s[i]=='('): | ||
| if (s[i]=='('): | ||
| stack.append(i) | ||
| else: | ||
| stack.pop() | ||
| if(len(stack)==0): | ||
| if not stack: | ||
|
Comment on lines
-12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| stack.append(i) | ||
| else: | ||
| ans=max(ans,i-stack[-1]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ def rotate(self, nums: List[int], k: int) -> None: | |
| Do not return anything, modify nums in-place instead. | ||
| """ | ||
| lenz = len(nums) | ||
| k = k % lenz | ||
| k %= lenz | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if k == 0: | ||
| return nums | ||
| nums += nums[:-k] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,20 +15,18 @@ def search(self, nums: List[int], target: int) -> int: | |
| mid = (low+high)//2 | ||
| if nums[mid]==target: | ||
| return mid | ||
| # if left half is sorted | ||
|
|
||
| # if left half is sorted | ||
| if nums[low]<=nums[mid]: | ||
| if nums[low]<=target<nums[mid]: | ||
| high = mid-1 | ||
| else: | ||
| low = mid+1 | ||
|
|
||
| # if right half is sorted | ||
|
|
||
| elif nums[mid]<target<=nums[high]: | ||
| low = mid+1 | ||
| else: | ||
| if nums[mid]<target<=nums[high]: | ||
| low = mid+1 | ||
| else: | ||
| high = mid-1 | ||
| high = mid-1 | ||
|
Comment on lines
-18
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| return -1 | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| class Solution: | ||
| def singleNumber(self, nums: List[int]) -> int: | ||
| d = dict() | ||
| for i in range(len(nums)) : | ||
| if nums[i] not in d : | ||
| d[nums[i]] = 1 | ||
| d = {} | ||
| for num in nums: | ||
| if num not in d: | ||
| d[num] = 1 | ||
| else: | ||
| d[nums[i]] += 1 | ||
| d[num] += 1 | ||
|
Comment on lines
-3
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for key, value in d.items() : | ||
| if value == 1 : | ||
| return key | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,8 @@ def isMatch(self, s: str, p: str) -> bool: | |
| m,n = len(p),len(s) | ||
| if len(p) - p.count("*") > len(s): | ||
| return False | ||
| dp = [[False]*(n+1) for i in range(m+1)] | ||
|
|
||
| dp = [[False]*(n+1) for _ in range(m+1)] | ||
|
Comment on lines
-51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for i in range(m+1): | ||
| for j in range(n+1): | ||
| if j==0 and i==0: | ||
|
|
@@ -58,7 +58,7 @@ def isMatch(self, s: str, p: str) -> bool: | |
| dp[i][j] = False | ||
| elif j==0: | ||
| dp[i][j] = (p[i-1]=="*" and dp[i-1][j]) | ||
| elif p[i-1] == s[j-1] or p[i-1]=='?': | ||
| elif p[i - 1] in [s[j - 1], '?']: | ||
| dp[i][j] = dp[i-1][j-1] | ||
| elif p[i-1]=='*': | ||
| dp[i][j] = dp[i-1][j] or dp[i][j-1] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
Solution.isSymmetricrefactored with the following changes:merge-list-appends-into-extend)