5 votes
Accepted

LeetCode Daily Problem: Remove adjacent duplicated elements

Use proper formatting. This may be very basic, but the impact on readability is hard to overstate. Compile your code with an appropriate warning-level. Trying will weed out many errors, and point out ...
  • 18.2k
5 votes

LeetCode Daily Problem: Remove adjacent duplicated elements

I had to remove the non-standard <io.stream> and add <string.h> to get a declarations of ...
2 votes

Find numbers whose factors, when squared, sum to a perfect square

Various details You initialise sum = 0 before the loop and then at the end of each iteration making it slightly harder to understand how it is being used and how ...
  • 29k
1 vote

Find numbers whose factors, when squared, sum to a perfect square

We can significantly improve performance by optimizing divisors searching. It suffices to check first sqrt(x) divisors, because for each divisor ...
  • 338
1 vote

Find numbers whose factors, when squared, sum to a perfect square

Finding all numbers' factors by trial division is going to be slow. We can make it faster by stopping when we reach √x, and adding both y and x/y to the list of factors (when y ≠ x/y, of course). ...

Only top scored, non community-wiki answers of a minimum length are eligible