Skip to content

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 22, 2022

Branch main 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 main branch, then run:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from xihuishawpy July 22, 2022 09:53
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.


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.twoSum:

Comment on lines -4 to +17
cache = [[False] * (len(p) + 1) for i in range(len(s) + 1)]
cache = [[False] * (len(p) + 1) for _ in range(len(s) + 1)]
cache[len(s)][len(p)] = True

for i in range(len(s), -1, -1):
for j in range(len(p) - 1, -1 ,-1):
match = i < len(s) and (s[i] == p[j] or p[j] == ".")

if (j + 1) < len(p) and p[j + 1] == "*":
cache[i][j] = cache[i][j + 2]
if match:
cache[i][j] = cache[i + 1][j] or cache[i][j]
elif match:
cache[i][j] = cache[i+1][j+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.isMatch refactored with the following changes:

Comment on lines -10 to +18
if not p and not q: return True
if p and q and p.val == q.val:
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
else: return False
if p or q:
return (
self.isSameTree(p.left, q.left)
and self.isSameTree(p.right, q.right)
if p and q and p.val == q.val
else False
)

else: return True
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.isSameTree refactored with the following changes:

Comment on lines -13 to +17

while q:
val = []
for i in range(len(q)):

for _ in range(len(q)):
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.levelOrder refactored with the following changes:

Comment on lines -4 to +8
if not root:
return 0

return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
return (
1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
if root
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.maxDepth refactored with the following changes:


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function LRUCache.__init__:

Comment on lines -5 to +9

for i, a in enumerate(nums):
if i > 0 and a == nums[i - 1]:
continue

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.threeSum:

Comment on lines -5 to -11
if c == "+":
if c == "*":
stack.append(stack.pop() * stack.pop())
elif c == "+":
stack.append(stack.pop() + stack.pop())
elif c == "-":
a, b = stack.pop(), stack.pop()
stack.append(b - a)
elif c == "*":
stack.append(stack.pop() * stack.pop())
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.evalRPN refactored with the following changes:

  • Simplify conditional into switch-like form (switch)

Comment on lines -6 to +8

for n in nums:

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.maxProduct:


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.minCostConnectPoints:


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.minInterval:

Comment on lines -11 to +22

while q:
rightSide = None
qLen = len(q)

for i in range(qLen):
node = q.popleft()
if node:

for _ in range(qLen):
if node := q.popleft():
rightSide = node
q.append(node.left)
q.append(node.right)
if rightSide:
res.append(rightSide.val)
res.append(rightSide.val)
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.rightSideView refactored with the following changes:

Comment on lines -10 to +21

carry = 0
while l1 or l2 or carry:
v1 = l1.val if l1 else 0
v2 = l2.val if l2 else 0

# new digit
val = v1 + v2 + carry
carry = val // 10
val = val % 10
cur.next = ListNode(val)

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.addTwoNumbers:


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.isValid:

Comment on lines -4 to +10

while slow != fast:
fast = self.sumSquareDigits(fast)
fast = self.sumSquareDigits(fast)
slow = self.sumSquareDigits(slow)

return True if fast == 1 else False
return fast == 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.isHappy refactored with the following changes:

Comment on lines -5 to +11

countS, countT = {}, {}

for i in range(len(s)):
countS[s[i]] = 1 + countS.get(s[i], 0)
countT[t[i]] = 1 + countT.get(t[i], 0)
for c in countS:
if countS[c] != countT.get(c, 0):
return False
return True
return all(value == countT.get(c, 0) for c, value in countS.items())
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.isAnagram refactored with the following changes:

res = len(nums)

for i in range(len(nums)):
res += (i - nums[i])
return res
return len(nums) + sum((i - nums[i]) for i in range(len(nums)))
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.missingNumber refactored with the following changes:

for i in range(nums.count(val)): # loop how many val is in the list
for _ in range(nums.count(val)):
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.removeElement refactored with the following changes:

This removes the following comments ( why? ):

# loop how many val is in the list

res = ""
for s in strs:
res += str(len(s)) + "#" + s
return res
return "".join(f"{len(s)}#{s}" for s in strs)
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.encode refactored with the following changes:

Comment on lines -3 to +5
if needle == "": return 0
if not needle: return 0
lps = [0] * len(needle)

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.strStr refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 22, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 1.68%.

Quality metrics Before After Change
Complexity 10.63 🙂 9.08 🙂 -1.55 👍
Method Length 71.28 🙂 65.65 🙂 -5.63 👍
Working memory 5.44 ⭐ 5.92 ⭐ 0.48 👎
Quality 68.12% 🙂 69.80% 🙂 1.68% 👍
Other metrics Before After Change
Lines 3086 2809 -277
Changed files Quality Before Quality After Quality Change
1-Two-Sum.py 84.36% ⭐ 84.36% ⭐ 0.00%
10-Regular-Expression-Matching.py 57.83% 🙂 57.83% 🙂 0.00%
100-Same-Tree.py 80.60% ⭐ 77.66% ⭐ -2.94% 👎
102-Binary-Tree-Level-Order-Traversal.py 72.73% 🙂 72.73% 🙂 0.00%
104-Maximum-Depth-of-Binary-Tree.py 82.06% ⭐ 81.00% ⭐ -1.06% 👎
11-Container-With-Most-Water.py 81.63% ⭐ 82.88% ⭐ 1.25% 👍
1143-Longest-Common-Subsequence.py 65.43% 🙂 67.78% 🙂 2.35% 👍
115-Distinct-Subsequences.py 64.46% 🙂 64.46% 🙂 0.00%
121-Best-Time-To-Buy-and-Sell-Stock.py 85.78% ⭐ 85.78% ⭐ 0.00%
127-Word-Ladder.py 44.62% 😞 46.68% 😞 2.06% 👍
128-Longest-consecutive-sequence.py 80.60% ⭐ 80.60% ⭐ 0.00%
138-Copy-List-With-Random-Pointer.py 81.37% ⭐ 81.37% ⭐ 0.00%
141-Linked-List-Cycle.py 89.05% ⭐ 89.05% ⭐ 0.00%
146-LRU-Cache.py 88.85% ⭐ 88.85% ⭐ 0.00%
15-3Sum.py 57.06% 🙂 57.06% 🙂 0.00%
150-Evaluate-Reverse-Polish-Notation.py 64.16% 🙂 64.16% 🙂 0.00%
152-Maximum-Product-Subarray.py 86.34% ⭐ 86.34% ⭐ 0.00%
1584-Min-Cost-to-Connect-all-Points.py 53.28% 🙂 53.28% 🙂 0.00%
1851-Minimum-Interval-to-Include-Each-Query.py 58.59% 🙂 58.59% 🙂 0.00%
199-Binary-Tree-Right-Side-View.py 75.51% ⭐ 75.67% ⭐ 0.16% 👍
2-Add-Two-Numbers.py 63.91% 🙂 63.91% 🙂 0.00%
20-Valid-Parentheses.py 81.88% ⭐ 81.88% ⭐ 0.00%
202-Happy-Number.py 89.96% ⭐ 90.76% ⭐ 0.80% 👍
208-Implement-Trie.py 88.16% ⭐ 88.16% ⭐ 0.00%
211-Design-Add-and-Search-Words-Data-Structure.py 81.85% ⭐ 81.85% ⭐ 0.00%
215-Kth-Largest-Element-in-an-Array.py 69.60% 🙂 98.17% ⭐ 28.57% 👍
217-Contains-Duplicate.py 94.18% ⭐ 94.18% ⭐ 0.00%
23-Merge-K-Sorted-Lists.py 70.00% 🙂 70.79% 🙂 0.79% 👍
230-Kth-Smallest-Element-in-a-BST.py 82.36% ⭐ 82.36% ⭐ 0.00%
236-Lowest-Common-Ancestor-of-a-Binary-Tree.py 69.23% 🙂 70.41% 🙂 1.18% 👍
238-Product-of-array-except-self.py 81.83% ⭐ 81.83% ⭐ 0.00%
242-Valid-Anagrams.py 73.51% 🙂 76.33% ⭐ 2.82% 👍
268-Missing-Number.py 93.35% ⭐ 94.51% ⭐ 1.16% 👍
27-Remove-Element.py 93.51% ⭐ 96.17% ⭐ 2.66% 👍
271-Encode-and-Decode-Strings.py 83.06% ⭐ 80.65% ⭐ -2.41% 👎
28-Implement-strStr.py 53.97% 🙂 56.59% 🙂 2.62% 👍
3-Longest-Substring-Without-Repeating-Characters.py 81.15% ⭐ 81.15% ⭐ 0.00%
312-Burst-Balloons.py 68.74% 🙂 68.74% 🙂 0.00%
323-Number-of-Connected-Components-in-an-Undirected-Graph.py 91.53% ⭐ 91.65% ⭐ 0.12% 👍
33-Search-In-Rotated-Sorted-Array.py 64.19% 🙂 66.68% 🙂 2.49% 👍
338-Counting-Bits.py 85.46% ⭐ 85.46% ⭐ 0.00%
347-Top-k-frequent-elements.py 69.89% 🙂 69.89% 🙂 0.00%
355-Design-Twitter.py 73.66% 🙂 73.66% 🙂 0.00%
371-Sum-of-Two-Integers.py 75.54% ⭐ 75.69% ⭐ 0.15% 👍
377-Combination-Sum-IV.py 75.26% ⭐ 85.95% ⭐ 10.69% 👍
394-decode-string.py 66.40% 🙂 66.40% 🙂 0.00%
4-median-of-two-sorted-arrays.py 37.43% 😞 37.43% 😞 0.00%
416-Partition-Equal-Subset-Sum.py 71.87% 🙂 72.62% 🙂 0.75% 👍
424-Longest-Repeating-Character-Replacement.py 70.19% 🙂 70.19% 🙂 0.00%
43-Number_of_Connected_Components_in_an_Undirected_Graph.py 74.85% 🙂 75.09% ⭐ 0.24% 👍
448-Find-all-Numbers-Disappeared-in-an-Array.py 83.99% ⭐ 85.70% ⭐ 1.71% 👍
46-Permutations.py 80.01% ⭐ 80.01% ⭐ 0.00%
473-Matchsticks-to-Square.py 74.81% 🙂 74.81% 🙂 0.00%
5-Longest-Palindromic-Substring.py 54.61% 🙂 54.61% 🙂 0.00%
50-Pow(x, n).py 83.52% ⭐ 83.52% ⭐ 0.00%
518-coin-change-2.py 52.88% 🙂 78.78% ⭐ 25.90% 👍
53-Maximum-Subarray.py 90.04% ⭐ 92.19% ⭐ 2.15% 👍
54-Spiral-Matrix.py 56.35% 🙂 61.22% 🙂 4.87% 👍
567-Permutation-in-String.py 50.15% 🙂 49.66% 😞 -0.49% 👎
572-Subtree-of-Another-Tree.py 83.88% ⭐ 82.96% ⭐ -0.92% 👎
62-Unique-Paths.py 84.03% ⭐ 84.03% ⭐ 0.00%
621-Task-Scheduler.py 63.49% 🙂 64.19% 🙂 0.70% 👍
658-Find-K-Closest-Elements.py 56.43% 🙂 56.43% 🙂 0.00%
66-Plus-One.py 75.82% ⭐ 75.82% ⭐ 0.00%
673-Number-of-Longest-Increasing-Subsequence.py 48.84% 😞 66.67% 🙂 17.83% 👍
678-Valid-Parenthesis-String.py 70.49% 🙂 71.33% 🙂 0.84% 👍
684-Redundant-Connection.py 72.04% 🙂 72.27% 🙂 0.23% 👍
7-Reverse-Integer.py 69.24% 🙂 69.83% 🙂 0.59% 👍
70-Climbing-Stairs.py 87.59% ⭐ 90.22% ⭐ 2.63% 👍
72-Edit-Distance.py 59.82% 🙂 59.82% 🙂 0.00%
724-Find-Pivot-Index.py 86.11% ⭐ 86.11% ⭐ 0.00%
739-Daily-Temperatures.py 73.29% 🙂 73.29% 🙂 0.00%
74-Search-a-2D-Matrix.py 57.09% 🙂 57.21% 🙂 0.12% 👍
743-Network-Delay-Time.py 61.21% 🙂 61.21% 🙂 0.00%
76-Minimum-Window-Substring.py 42.24% 😞 42.33% 😞 0.09% 👍
763-Partition-Labels.py 69.93% 🙂 69.93% 🙂 0.00%
767-Reorganize-String.py 69.10% 🙂 69.10% 🙂 0.00%
778-Swim-in-Rising-Water.py 53.21% 🙂 53.80% 🙂 0.59% 👍
787-Cheapest-Flights-within-K-stops.py 67.31% 🙂 67.31% 🙂 0.00%
84-Largest-Rectangle-in-Histogram.py 65.14% 🙂 65.14% 🙂 0.00%
846-Hand-of-Straights.py 65.00% 🙂 65.00% 🙂 0.00%
875-Koko-Eating-Bananas.py 72.30% 🙂 72.05% 🙂 -0.25% 👎
909-Snakes-and-Ladders.py 68.17% 🙂 68.17% 🙂 0.00%
91-Decode-ways.py 60.34% 🙂 77.15% ⭐ 16.81% 👍
92-Reverse-Linked-List-II.py 74.42% 🙂 76.77% ⭐ 2.35% 👍
94-Binary-Tree-Inorder-Traversal.py 80.64% ⭐ 86.94% ⭐ 6.30% 👍
97-Interleaving-Strings.py 54.56% 🙂 54.56% 🙂 0.00%
973-K-Closest-Points-to-Origin.py 75.17% ⭐ 75.17% ⭐ 0.00%
98-Validate-Binary-Search-Tree.py 84.14% ⭐ 84.30% ⭐ 0.16% 👍
994-Rotting-Oranges.py 40.13% 😞 40.13% 😞 0.00%
python/10-Regular-Expression-Matching.py 57.83% 🙂 57.83% 🙂 0.00%
python/100-Same-Tree.py 80.60% ⭐ 77.66% ⭐ -2.94% 👎
python/102-Binary-Tree-Level-Order-Traversal.py 72.73% 🙂 72.73% 🙂 0.00%
python/104-Maximum-Depth-of-Binary-Tree.py 82.06% ⭐ 81.00% ⭐ -1.06% 👎
python/11-Container-With-Most-Water.py 81.63% ⭐ 82.88% ⭐ 1.25% 👍
python/1143-Longest-Common-Subsequence.py 65.43% 🙂 67.78% 🙂 2.35% 👍
python/1209-Remove-All-Adjacent-Duplicates-in-String-II.py 75.20% ⭐ 76.46% ⭐ 1.26% 👍
python/127-Word-Ladder.py 44.62% 😞 46.68% 😞 2.06% 👍
python/150-Evaluate-Reverse-Polish-Notation.py 64.16% 🙂 64.16% 🙂 0.00%
python/199-Binary-Tree-Right-Side-View.py 75.51% ⭐ 75.67% ⭐ 0.16% 👍
python/202-Happy-Number.py 89.96% ⭐ 90.76% ⭐ 0.80% 👍
python/208-Implement-Trie.py 88.16% ⭐ 88.16% ⭐ 0.00%
python/215-Kth-Largest-Element-in-an-Array.py 69.60% 🙂 98.17% ⭐ 28.57% 👍
python/23-Merge-K-Sorted-Lists.py 70.00% 🙂 70.79% 🙂 0.79% 👍
python/236-Lowest-Common-Ancestor-of-a-Binary-Tree.py 69.23% 🙂 70.41% 🙂 1.18% 👍
python/268-Missing-Number.py 93.35% ⭐ 94.51% ⭐ 1.16% 👍
python/27-Remove-Element.py 93.51% ⭐ 96.17% ⭐ 2.66% 👍
python/271-Encode-and-Decode-Strings.py 83.06% ⭐ 80.65% ⭐ -2.41% 👎
python/28-Implement-strStr.py 53.97% 🙂 56.59% 🙂 2.62% 👍
python/323-Number-of-Connected-Components-in-an-Undirected-Graph.py 91.53% ⭐ 91.65% ⭐ 0.12% 👍
python/33-Search-In-Rotated-Sorted-Array.py 64.19% 🙂 66.68% 🙂 2.49% 👍
python/347-Top-k-frequent-elements.py 69.89% 🙂 69.89% 🙂 0.00%
python/371-Sum-of-Two-Integers.py 75.54% ⭐ 75.69% ⭐ 0.15% 👍
python/377-Combination-Sum-IV.py 75.26% ⭐ 85.95% ⭐ 10.69% 👍
python/416-Partition-Equal-Subset-Sum.py 71.87% 🙂 72.62% 🙂 0.75% 👍
python/43-Number_of_Connected_Components_in_an_Undirected_Graph.py 74.85% 🙂 75.09% ⭐ 0.24% 👍
python/448-Find-all-Numbers-Disappeared-in-an-Array.py 83.99% ⭐ 85.70% ⭐ 1.71% 👍
python/46-Permutations.py 80.01% ⭐ 80.01% ⭐ 0.00%
python/50-Pow(x, n).py 83.52% ⭐ 83.52% ⭐ 0.00%
python/518-coin-change-2.py 52.88% 🙂 78.78% ⭐ 25.90% 👍
python/53-Maximum-Subarray.py 90.04% ⭐ 92.19% ⭐ 2.15% 👍
python/54-Spiral-Matrix.py 56.35% 🙂 61.22% 🙂 4.87% 👍
python/567-Permutation-in-String.py 50.15% 🙂 49.66% 😞 -0.49% 👎
python/572-Subtree-of-Another-Tree.py 83.88% ⭐ 82.96% ⭐ -0.92% 👎
python/62-Unique-Paths.py 84.03% ⭐ 84.03% ⭐ 0.00%
python/621-Task-Scheduler.py 63.49% 🙂 64.19% 🙂 0.70% 👍
python/658-Find-K-Closest-Elements.py 56.43% 🙂 56.43% 🙂 0.00%
python/673-Number-of-Longest-Increasing-Subsequence.py 48.84% 😞 66.67% 🙂 17.83% 👍
python/678-Valid-Parenthesis-String.py 70.49% 🙂 71.33% 🙂 0.84% 👍
python/684-Redundant-Connection.py 72.04% 🙂 72.27% 🙂 0.23% 👍
python/7-Reverse-Integer.py 69.24% 🙂 69.83% 🙂 0.59% 👍
python/70-Climbing-Stairs.py 87.59% ⭐ 90.22% ⭐ 2.63% 👍
python/72-Edit-Distance.py 59.82% 🙂 59.82% 🙂 0.00%
python/74-Search-a-2D-Matrix.py 57.09% 🙂 57.21% 🙂 0.12% 👍
python/76-Minimum-Window-Substring.py 42.24% 😞 42.33% 😞 0.09% 👍
python/778-Swim-in-Rising-Water.py 53.21% 🙂 53.80% 🙂 0.59% 👍
python/787-Cheapest-Flights-within-K-stops.py 67.31% 🙂 67.31% 🙂 0.00%
python/853-Car-Fleet.py 75.99% ⭐ 79.38% ⭐ 3.39% 👍
python/875-Koko-Eating-Bananas.py 72.30% 🙂 72.05% 🙂 -0.25% 👎
python/909-Snakes-and-Ladders.py 68.17% 🙂 68.17% 🙂 0.00%
python/91-Decode-ways.py 60.34% 🙂 77.15% ⭐ 16.81% 👍
python/92-Reverse-Linked-List-II.py 74.42% 🙂 76.77% ⭐ 2.35% 👍
python/94-Binary-Tree-Inorder-Traversal.py 80.64% ⭐ 86.94% ⭐ 6.30% 👍
python/97-Interleaving-Strings.py 54.56% 🙂 54.56% 🙂 0.00%
python/973-K-Closest-Points-to-Origin.py 75.17% ⭐ 75.17% ⭐ 0.00%
python/98-Validate-Binary-Search-Tree.py 84.14% ⭐ 84.30% ⭐ 0.16% 👍
python/994-Rotting-Oranges.py 40.13% 😞 40.13% 😞 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
4-median-of-two-sorted-arrays.py Solution.findMedianSortedArrays 18 🙂 175 😞 14 😞 37.43% 😞 Try splitting into smaller methods. Extract out complex expressions
994-Rotting-Oranges.py Solution.orangesRotting 22 😞 166 😞 11 😞 40.13% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
python/994-Rotting-Oranges.py Solution.orangesRotting 22 😞 166 😞 11 😞 40.13% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
76-Minimum-Window-Substring.py Solution.minWindow 16 🙂 171 😞 12 😞 42.33% 😞 Try splitting into smaller methods. Extract out complex expressions
python/76-Minimum-Window-Substring.py Solution.minWindow 16 🙂 171 😞 12 😞 42.33% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.lengthOfLongestSubstring:


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.maxCoins:

Comment on lines 18 to 19
return len(set(dsu.findParent(x) for x in range(n))) No newline at end of file
return len({dsu.findParent(x) for x 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.countComponents refactored with the following changes:

Comment on lines -4 to +19

while l <= r:
mid = (l + r) // 2
if target == nums[mid]:
return mid

# left sorted portion
if nums[l] <= nums[mid]:
if target > nums[mid] or target < nums[l]:
l = mid + 1
else:
r = mid - 1
# right sorted portion
elif target < nums[mid] or target > nums[r]:
r = mid - 1
else:
if target < nums[mid] or target > nums[r]:
r = mid - 1
else:
l = mid + 1
l = mid + 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.search refactored with the following changes:

This removes the following comments ( why? ):

# right sorted portion


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.countBits:

Comment on lines -4 to +12

# base case
if len(nums) == 1:
return [nums[:]] # nums[:] is a deep copy
for i in range(len(nums)):

for _ in range(len(nums)):
n = nums.pop(0)
perms = self.permute(nums)

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.permute refactored with the following changes:

Comment on lines -5 to +12

if sum(matchsticks) / 4 != length:
return False
matchsticks.sort(reverse=True)
def backtrack(i):
if i == len(matchsticks):
return True

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.makesquare:


Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Solution.longestPalindrome:

Comment on lines -6 to +9
res = helper(x * x, n // 2)

res = helper(x**2, n // 2)
return x * res if n % 2 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:


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.change refactored with the following changes:

This removes the following comments ( why? ):

# Time: O(n*m)
# Memory: O(n*m)
# Memory: O(n) where n = amount
# DYNAMIC PROGRAMMING

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