fork download
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. # def __init__(self, val=0, next=None):
  4. # self.val = val
  5. # self.next = next
  6. class Solution:
  7. def reorderList(self, head: Optional[ListNode]) -> None:
  8. """
  9. Do not return anything, modify head in-place instead.
  10. """
  11. slow = fast = head
  12. while fast.next and fast.next.next:
  13. slow = slow.next
  14. fast = fast.next.next
  15.  
  16. prev, curr = None, slow.next
  17. while curr:
  18. curr.next, prev, curr = prev, curr, curr.next
  19. slow.next = None
  20.  
  21. head1, head2 = head, prev
  22. while head2:
  23. head1.next, head1, head2 = head2, head2, head1.next
  24.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
# Definition for singly-linked list.
^
Main.java:1: error: class, interface, or enum expected
# Definition for singly-linked list.
             ^
Main.java:2: error: illegal character: '#'
# class ListNode:
^
Main.java:2: error: '{' expected
# class ListNode:
                ^
Main.java:3: error: illegal character: '#'
#     def __init__(self, val=0, next=None):
^
Main.java:4: error: illegal character: '#'
#         self.val = val
^
Main.java:5: error: illegal character: '#'
#         self.next = next
^
Main.java:6: error: '{' expected
class Solution:
              ^
Main.java:8: error: unclosed string literal
        """
          ^
Main.java:10: error: unclosed string literal
        """
          ^
Main.java:23: error: reached end of file while parsing
            head1.next, head1, head2 = head2, head2, head1.next
                                                               ^
11 errors
stdout
Standard output is empty