Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

This solution is equivalent to the one in the accepted answer accepted answer of the question you linked. The expression you used is the 1D-array equivalent of how that answer derived the appropriate (row, col) indexes in a 2D-array. The time complexity is \$O(N^2)\$, because in an NxN matrix there are \$N^2\$ cells, and your main operation visits all of them. You have some extra costs due to .rstrip() and .replace() but those don't change the asymptotic complexity.

In terms of Python coding, you forgot to close the file you opened after reading. You should wrap the loop inside a with open(...) as fh:, iterate over fh, and it will be automatically closed when leaving the with block.

This solution is equivalent to the one in the accepted answer of the question you linked. The expression you used is the 1D-array equivalent of how that answer derived the appropriate (row, col) indexes in a 2D-array. The time complexity is \$O(N^2)\$, because in an NxN matrix there are \$N^2\$ cells, and your main operation visits all of them. You have some extra costs due to .rstrip() and .replace() but those don't change the asymptotic complexity.

In terms of Python coding, you forgot to close the file you opened after reading. You should wrap the loop inside a with open(...) as fh:, iterate over fh, and it will be automatically closed when leaving the with block.

This solution is equivalent to the one in the accepted answer of the question you linked. The expression you used is the 1D-array equivalent of how that answer derived the appropriate (row, col) indexes in a 2D-array. The time complexity is \$O(N^2)\$, because in an NxN matrix there are \$N^2\$ cells, and your main operation visits all of them. You have some extra costs due to .rstrip() and .replace() but those don't change the asymptotic complexity.

In terms of Python coding, you forgot to close the file you opened after reading. You should wrap the loop inside a with open(...) as fh:, iterate over fh, and it will be automatically closed when leaving the with block.

Source Link
janos
  • 112.9k
  • 15
  • 154
  • 396

This solution is equivalent to the one in the accepted answer of the question you linked. The expression you used is the 1D-array equivalent of how that answer derived the appropriate (row, col) indexes in a 2D-array. The time complexity is \$O(N^2)\$, because in an NxN matrix there are \$N^2\$ cells, and your main operation visits all of them. You have some extra costs due to .rstrip() and .replace() but those don't change the asymptotic complexity.

In terms of Python coding, you forgot to close the file you opened after reading. You should wrap the loop inside a with open(...) as fh:, iterate over fh, and it will be automatically closed when leaving the with block.

lang-py

AltStyle によって変換されたページ (->オリジナル) /