Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- github
- Git
- SW Expert Academy
- gs25
- 백준
- ubuntu
- Real or Not? NLP with Disaster Tweets
- Docker
- PYTHON
- AI 경진대회
- Kaggle
- programmers
- 더현대서울 맛집
- 프로그래머스 파이썬
- 프로그래머스
- ChatGPT
- 캐치카페
- 자연어처리
- 우분투
- 파이썬
- 데이콘
- Baekjoon
- 맥북
- hackerrank
- leetcode
- 편스토랑 우승상품
- dacon
- 편스토랑
- 코로나19
- 금융문자분석경진대회
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 203. Remove Linked List Elements (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 203. Remove Linked List Elements (Python)
솜씨좋은장씨 2020. 9. 29. 15:43728x90
반응형

Remove all elements from a linked list of integers that have value val.
Example:
Input: 1->2->6->3->4->5->6, val = 6
Output: 1->2->3->4->5
Solution
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode:
while head and head.val == val:
head = head.next
if not head:
return head
next_node = head
while next_node and next_node.next:
if next_node.next.val == val:
next_node.next = next_node.next.next
else:
next_node = next_node.next
return head



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 190. Reverse Bits (Python) (0) | 2020.10.01 |
|---|---|
| [leetCode] 234. Palindrome Linked List (Python) (0) | 2020.09.30 |
| [leetCode] 1417. Reformat The String (Python) (0) | 2020.09.28 |
| [leetCode] 1051. Height Checker (Python) (0) | 2020.09.27 |
| [leetCode] 925. Long Pressed Name (Python) (0) | 2020.09.25 |
Comments