| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- Decorator
- 109. Convert Sorted List to Binary Search Tree
- LeetCode
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- 30. Substring with Concatenation of All Words
- DWG
- 운영체제
- 파이썬
- Protocol
- Convert Sorted List to Binary Search Tree
- Regular Expression
- 밴픽
- Substring with Concatenation of All Words
- kaggle
- attribute
- shiba
- iterator
- 43. Multiply Strings
- Python
- Python Implementation
- 컴퓨터의 구조
- 715. Range Module
- Generator
- Class
- 시바견
- concurrency
- Python Code
- data science
- t1
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 |