AC
1 |
def (self, head): |
Time complexity: O(1.5n)
Space Complexity: O(1)
loop through all node once to find index of middle node
loop second time to find the node at middle index
Best Answer
reduce time complexity
1 |
def middleNodeQuicker(self,head): |
Time complexity: O(0.5n)
Space Complexity: O(1)
have fast pointer go two node each time, so it will tun 1/2 n time
the slow pointer will go one node each time and stop at mid node
近期评论