Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1418 from imevanc/Create-83-Remove-Dup…
Browse files Browse the repository at this point in the history
…licates-From-Sorted-List

Create: 83-Remove-Duplicates-From-Sorted-List.js
  • Loading branch information
Ahmad-A0 authored Nov 5, 2022
2 parents aa783df + c4b5b0e commit 4e9bb36
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions javascript/83-Remove-Duplicates-From-Sorted-List.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* https://leetcode.com/problems/remove-duplicates-from-sorted-list/
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var deleteDuplicates = function (head) {
let cur = head;
while (cur != null && cur.next != null) {
if (cur.next.val === cur.val) {
cur.next = cur.next.next;
} else {
cur = cur.next;
}
}
return head;
};

0 comments on commit 4e9bb36

Please sign in to comment.