소스 검색

New problem done

master
Lachlan Jacob 5 년 전
부모
커밋
c5a83a58ed
3개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. 40
    0
      problems/83/main.js
  2. 13
    0
      problems/83/problem.txt
  3. 3
    0
      problems/83/run.sh

+ 40
- 0
problems/83/main.js 파일 보기

@@ -0,0 +1,40 @@
/**
* 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 prev = null;
let current = head;
let found = {};
while (current != null) {
if (current.val in found) {
prev.next = current.next;
current = current.next;
} else {
found[current.val] = true;
prev = current;
current = current.next;
}
}
return head;
};

const printLinkedList = (ll) => {
while (ll != null) {
console.log(ll.val);
ll = ll.next;
}
};

console.log("Expected: 1->2");
let ll = new ListNode(1, new ListNode(1, new ListNode(2)));
console.log(`Got:`);
printLinkedList(deleteDuplicates(ll));

+ 13
- 0
problems/83/problem.txt 파일 보기

@@ -0,0 +1,13 @@
Given a sorted linked list, delete all duplicates such that each element appear only once.

Example 1:

Input: 1->1->2
Output: 1->2

Example 2:

Input: 1->1->2->3->3
Output: 1->2->3



+ 3
- 0
problems/83/run.sh 파일 보기

@@ -0,0 +1,3 @@
#!/bin/bash

node main.js

Loading…
취소
저장