일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- BOJ
- machine learning
- C#
- JavaScript
- var
- bash
- generic
- condition
- AI
- loop
- security
- Python
- npm
- git
- nginx
- scss
- dotenv
- C++
- VUE
- leetcode
- vuetify
- 앙상블
- 보안
- vue.js
- TypeScript
- Clone
- type
- docker
- property
- webpack
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Remove Duplicates From Sorted List 본문
https://leetcode.com/problems/remove-duplicates-from-sorted-list/
[
Remove Duplicates from Sorted List - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
](https://leetcode.com/problems/remove-duplicates-from-sorted-list/)
이 문제와 비슷한데, 여기서는 배열이 아닌 List이다. value가 같으면 연결을 끊고 그 다음을 연결했다. null 검사를 통해 루프를 탈출.
// C#
/**
* Definition for singly-linked list.
* public class ListNode {
* public int val;
* public ListNode next;
* public ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode DeleteDuplicates(ListNode head) {
ListNode cmpTemp = head;
if(cmpTemp==null)
return head;
while(cmpTemp.next!=null) {
if(cmpTemp.val==cmpTemp.next.val) {
cmpTemp.next = cmpTemp.next.next;
continue;
}
cmpTemp = cmpTemp.next;
}
return head;
}
}
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] Two Sum II - Input array is sorted (0) | 2020.04.18 |
---|---|
[LeetCode] Linked List Cycle (0) | 2020.04.16 |
[LeetCode] Climbing Stairs (0) | 2020.04.15 |
[LeetCode] Maximum Subarray (0) | 2020.04.15 |
[LeetCode] Valid Parenthese (0) | 2020.04.15 |