Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- database
- 파이썬
- 자바
- Binary Search
- array
- dynamic programming
- geometry
- 구현
- Stack
- greedy
- Data Structure
- hash table
- Number Theory
- bit manipulation
- 코테
- 코딩테스트
- Math
- Method
- implement
- simulation
- sorting
- Matrix
- string
- two pointers
- Binary Tree
- Tree
- Counting
- java
- Class
- SQL
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 83. Remove Duplicates from Sorted List 본문
1. Input
1) ListNode head
2. Output
1) 정렬된 연결 리스트 head에서 모든 중복을 제외한 결과 리스트를 반환
3. Constraint
1) 노드 수의 범위는 [0, 300]이다.
2) -100 <= Node.val <= 100
3) 리스트는 오름차순으로 정렬되어 있다.
4. Example
Input: head = [1,1,2] -> Output: [1,2]
Input: head = [1,1,2,3,3] -> Output: [1,2,3]
5. Code
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode current = head;
while(current!=null){
if(current.next!=null && current.val == current.next.val){
if(current.next.next!=null)
current.next = current.next.next;
else
current.next = null;
}
else
current = current.next;
}
return head;
}
}
- 100%, 63%
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 108. Convert Sorted Array to Binary Search Tree (0) | 2023.07.18 |
---|---|
[LeetCode/Easy] 101. Symmetric Tree (0) | 2023.07.17 |
[LeetCode/Easy] 35. Search Insert Position (0) | 2023.07.17 |
[백준 온라인 저지] 1904. 01타일 (0) | 2023.07.14 |
[백준 온라인 저지] 11659. 구간 합 구하기 4 (0) | 2023.07.09 |