일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- concurrency
- 시바견
- iterator
- LeetCode
- Python Implementation
- kaggle
- Decorator
- shiba
- attribute
- Protocol
- 밴픽
- Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- Python Code
- 운영체제
- Substring with Concatenation of All Words
- t1
- 컴퓨터의 구조
- 315. Count of Smaller Numbers After Self
- 43. Multiply Strings
- 프로그래머스
- Regular Expression
- DWG
- 715. Range Module
- data science
- Class
- 파이썬
- Python
- 109. Convert Sorted List to Binary Search Tree
- Generator
Archives
- Today
- Total
Scribbling
LeetCode: 328. Odd Even Linked List 본문
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
if not head:
return None
odd_ptr = head
even_ptr = even_head = ListNode()
cur = head.next
cnt = 2
while cur != None:
if cnt % 2 != 0:
odd_ptr.next = cur
odd_ptr = cur
else:
even_ptr.next = cur
even_ptr = cur
cur = cur.next
cnt += 1
even_ptr.next = None
odd_ptr.next = even_head.next
return head
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 1010. Pairs of Songs With Total Durations Divisible by 60 (0) | 2022.01.03 |
---|---|
LeetCode: 297. Serialize and Deserialize Binary Tree (0) | 2022.01.02 |
LeetCode: 289. Game of Life (0) | 2021.12.29 |
LeetCode: 287. Find the Duplicate Number (0) | 2021.12.28 |
LeetCode: 279. Perfect Squares (0) | 2021.12.27 |