Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Apr 8, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from JoshuaNgugi April 8, 2023 07:42
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -9 to +12
print("Creating " + file_name + "in java and python dir...")
with open("python/" + file_name + ".py", 'w'):
print(f"Creating {file_name}in java and python dir...")
with open(f"python/{file_name}.py", 'w'):
pass
with open("java/" + file_name + ".java", 'w'):
with open(f"java/{file_name}.java", 'w'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 9-12 refactored with the following changes:

temp_s = '#'.join('{}'.format(s))
temp_s = '#'.join(f'{s}')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.longestPalindrome refactored with the following changes:

Comment on lines -4 to +14
flag = True if x < 0 else False
flag = x < 0
if flag:
x = -x
x = str(x)[::-1]

if flag:
x = "-" + x
x = f"-{x}"

value = 2 ** 31
x = int(x)
if -value <= x < value:
return x
return 0
return x if -value <= x < value else 0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.reverse refactored with the following changes:

Comment on lines -13 to +22
if pos < ls and str[pos] == '-':
sign = -1
pos += 1
elif pos < ls and str[pos] == '+':
pos += 1
if pos < ls:
if str[pos] == '-':
sign = -1
pos += 1
elif str[pos] == '+':
pos += 1
while pos < ls and ord(str[pos]) >= ord('0') and ord(str[pos]) <= ord('9'):
num = ord(str[pos]) - ord('0')
if result > max_int / 10 or ( result == max_int / 10 and num >= 8):
if sign == -1:
return min_int
return max_int
return min_int if sign == -1 else max_int
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.myAtoi refactored with the following changes:

if (x == x[::-1]):
return True
return False
return x == x[::-1]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.isPalindrome refactored with the following changes:

Comment on lines -12 to +14
for j in range(i + 1, ls):
# append ascending order pair
if nums[i] < nums[j]:
pair.append([i,j])
pair.extend([i,j] for j in range(i + 1, ls) if nums[i] < nums[j])
pos = 0
if len(pair) > 0:
if pair:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.nextPermutation refactored with the following changes:

This removes the following comments ( why? ):

# append ascending order pair

Comment on lines -31 to +33
else:
if len(stack) > 0:
data[i] = 1
data[stack.pop(-1)] = 1
elif stack:
data[i] = 1
data[stack.pop(-1)] = 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.longestValidParentheses refactored with the following changes:

Comment on lines -26 to +33
l, r = int(0), len(nums) - 1
l, r = 0, len(nums) - 1
while l < r:
mid = int((l + r) / 2)
if nums[mid] < target:
l = mid + 1
else:
r = mid
if nums[l] < target:
return l + 1
return l
return l + 1 if nums[l] < target else l
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.searchInsert refactored with the following changes:

for j in range(9):
if board[i][j] == '.':
empty.append(9 * i + j)
empty.extend(9 * i + j for j in range(9) if board[i][j] == '.')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.solveSudoku refactored with the following changes:

Comment on lines -40 to +42
step = 0
for index in range(start + 1, end):
if height[index] > 0:
step += height[index]
step = sum(
height[index] for index in range(start + 1, end) if height[index] > 0
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.rain_water refactored with the following changes:

if n < 0:
return 1 / res
return res
return 1 / res if n < 0 else res
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.myPow refactored with the following changes:

board = [['.'] * n for t in range(n)]
board = [['.'] * n for _ in range(n)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.solveNQueens refactored with the following changes:

Comment on lines -20 to +24
matrix[r_end][c_start:c_end + 1][::-1] +\
[matrix[j][c_start] for j in reversed(range(r_start + 1, r_end))]
res = curr + self.get_spiralOrder(matrix, r_start + 1, r_end - 1, c_start + 1, c_end - 1)
return res
matrix[r_end][c_start:c_end + 1][::-1] +\
[matrix[j][c_start] for j in reversed(range(r_start + 1, r_end))]
return curr + self.get_spiralOrder(
matrix, r_start + 1, r_end - 1, c_start + 1, c_end - 1
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.get_spiralOrder refactored with the following changes:

Comment on lines -34 to +39
if curr_int.start <= new_int.start:
if curr_int.end > new_int.start:
return True
else:
if curr_int.start <= new_int.end:
return True
return False
return (
curr_int.start <= new_int.start
and curr_int.end > new_int.start
or curr_int.start > new_int.start
and curr_int.start <= new_int.end
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.check_overlap refactored with the following changes:

Comment on lines 10 to 11
if len(temp) == 0:
return 0
else:
return len(temp[-1]) No newline at end of file
return len(temp[-1]) if temp else 0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.lengthOfLastWord refactored with the following changes:

Comment on lines -14 to +18
while j < length:
if nums[j] != nums[i]:
break
while j < length and nums[j] == nums[i]:
j += 1
if j-i > 2:
length -= j-i-2
for k in range(j-i-2):
for _ in range(j-i-2):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.removeDuplicates refactored with the following changes:

for j in reversed(range(len(res))):
res.append(res[j] + (1 << i))
res.extend(res[j] + (1 << i) for j in reversed(range(len(res))))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.grayCode refactored with the following changes:

if m == 1:
return prev
return head
return prev if m == 1 else head
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.reverseBetween refactored with the following changes:

Comment on lines -48 to +54
add1 = s[0:i]
add1 = s[:i]
add2 = s[i:i + j]
add3 = s[i + j:i + j + k]
add4 = s[i + j + k:]
if self.isValid(add1) and self.isValid(add2) and \
self.isValid(add3) and self.isValid(add4):
res.append(add1 + '.' + add2 + '.' + add3 + '.' + add4)
self.isValid(add3) and self.isValid(add4):
res.append(f'{add1}.{add2}.{add3}.{add4}')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.restoreIpAddresses refactored with the following changes:

if add[0] == '0':
return False
if int(add) <= 255:
return True
return False
return False if add[0] == '0' else int(add) <= 255
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Solution.isValid refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants