/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function(head) {
  var hash = new Set();
  var current = head;
  var pre = null;

  while (current) {
    var val = current.val;

    if (hash.has(val)) {
      pre.next = current.next;
    } else {
      pre = current;
      hash.add(val);
      console.log(hash.keys(), val)
    }

    current = current.next;
  }

  console.log(hash.values())
};

var eq = require('assert').deepEqual;
var nodeList = require('./_util').nodeList;

var l = nodeList.create([1, 2, 2, 1, 3]);
deleteDuplicates(l);
eq(nodeList.toArray(l), [1,2,3]);

@@ -444,44 +444,8 @@
 l);%0A
-      console.log(hash.keys(), val)%0A
     
@@ -486,34 +486,20 @@
 %0A%0A  
-console.log(hash.values())
+return head;
 %0A%7D;%0A
@@ -581,21 +581,24 @@
 deList;%0A
-%0A
 var 
+l;%0A%0A
 l = node
@@ -631,59 +631,206 @@
 %5D);%0A
-deleteDuplicates(l);%0Aeq(nodeList.toArray(l), %5B1,2,3
+eq(nodeList.toArray(deleteDuplicates(l)), %5B1,2,3%5D);%0A%0Al = nodeList.create(%5B1, 1%5D);%0Aeq(nodeList.toArray(deleteDuplicates(l)), %5B1%5D);%0Al = nodeList.create(%5B%5D);%0Aeq(nodeList.toArray(deleteDuplicates(l)), %5B
 %5D);%0A

Remove Duplicates from Sorted List: O(n) space solution