Skip to main content
add item about counted repetition
Source Link
greybeard
  • 7.8k
  • 3
  • 21
  • 56
  • document/comment your code. In the code.
  • re-checking .next in the second loop is unusually defensive
  • do not have a comment repeat what a statement "does" (reset node to point to head):
    have it illuminate what is achieved/what-for/why something is done (the way it is)
  • the ruby way to have a statement executed, say, middle times may be
    middle.times do
        node = node.next
    

(Eyeballing remove_middle_node, it uses O(1) additional space and Θ(n) time.)

  • document/comment your code. In the code.
  • re-checking .next in the second loop is unusually defensive
  • do not have a comment repeat what a statement "does" (reset node to point to head):
    have it illuminate what is achieved/what-for/why something is done (the way it is)

(Eyeballing remove_middle_node, it uses O(1) additional space and Θ(n) time.)

  • document/comment your code. In the code.
  • re-checking .next in the second loop is unusually defensive
  • do not have a comment repeat what a statement "does" (reset node to point to head):
    have it illuminate what is achieved/what-for/why something is done (the way it is)
  • the ruby way to have a statement executed, say, middle times may be
    middle.times do
        node = node.next
    

(Eyeballing remove_middle_node, it uses O(1) additional space and Θ(n) time.)

Source Link
greybeard
  • 7.8k
  • 3
  • 21
  • 56

  • document/comment your code. In the code.
  • re-checking .next in the second loop is unusually defensive
  • do not have a comment repeat what a statement "does" (reset node to point to head):
    have it illuminate what is achieved/what-for/why something is done (the way it is)

(Eyeballing remove_middle_node, it uses O(1) additional space and Θ(n) time.)