This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| A = 1, 3 | |
| B = 2, 4 | |
| C = | |
| min(min(A), min(B)) = 1 | |
| A = 3 | |
| B = 2, 4 | |
| C = 1 | |
| min(min(A), min(B)) = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def sortList(self, head): | |
| if not head or not head.next: | |
| return head | |
| fast, slow = head.next, head | |
| while fast and fast.next: | |
| fast = fast.next.next | |
| slow = slow.next | |
| start = slow.next | |
| slow.next = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List | |
| class Solution: | |
| def sortArrayByParityII(self, nums: List[int]) -> List[int]: | |
| res = [0] * len(nums) | |
| even, odd = 0, 1 | |
| for x in nums: | |
| if x & 1: | |
| res[odd] = x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def sortList(self, head): | |
| if not head or not head.next: | |
| return head | |
| fast, slow = head.next, head | |
| while fast and fast.next: | |
| fast = fast.next.next | |
| slow = slow.next | |
| start = slow.next | |
| slow.next = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def sortList(self, head): | |
| if not head or not head.next: | |
| return head | |
| fast, slow = head.next, head | |
| while fast and fast.next: | |
| fast = fast.next.next | |
| slow = slow.next | |
| start = slow.next | |
| slow.next = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| verification test |