Algorithm

class Solution {
public ListNode reverseList(ListNode head) {
ListNode prev = null;
ListNode curr = head;
while (curr != null) {
ListNode next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
}

Review


Algorithm

  • (optional) It can be skipped automatically if start with spaces( ).
  • (Optional) +/- can be used to record whether the number is positive or negative.
  • (mandatory) isDigit(ch) == true is the number One thing to note is.
  • (Must be…

Algorithm


Algorithm

Input array [1,2,3,4,5,6,7], k = 3
Output array: [5,6,7,1,2,3,4]
Explanation:
Rotate 1 steps to the right: [7,1,2,3,4,5,6]
Rotate 2 steps to the right: [6,7,1,2,3,4,5]
Rotate 3 steps to the right: [5,6,7,1,2,3,4]

KeepNewbie_yan

A programmer. Share knowledge of programming, operating system, Linux kernel, and reading, thinking etc. Let us maintain a beginner mend and grow together!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store