diff --git a/81-90/82. Remove Duplicates from Sorted List II.js b/81-90/82. Remove Duplicates from Sorted List II.js new file mode 100644 index 0000000..da6ff65 --- /dev/null +++ b/81-90/82. Remove Duplicates from Sorted List II.js @@ -0,0 +1,18 @@ +var deleteDuplicates = function(head) { + let obj = {} + while(head != null){ + obj[head.val] = (obj[head.val])?obj[head.val]+1:1 + head = head.next + } + let a = [] + for(let c in obj){ + if(obj[c] == 1){a.push(c)} + } + a.sort((a,b)=>{return a-b}) + let n = new ListNode() + let ans = n + for(let i = 0 ; i < a.length ; i++){ + n = n.next = new ListNode(a[i]) + } + return ans.next +}; \ No newline at end of file diff --git a/81-90/83. Remove Duplicates from Sorted List.js b/81-90/83. Remove Duplicates from Sorted List.js new file mode 100644 index 0000000..ef619a4 --- /dev/null +++ b/81-90/83. Remove Duplicates from Sorted List.js @@ -0,0 +1,13 @@ +var deleteDuplicates = function(head) { + let a = new Set() + let b = new ListNode(0) + let c = b + while(head != null ){ + a.add(head.val) + head = head.next + } + for(let x of a){ + b = b.next = new ListNode(x) + } + return c.next +}; \ No newline at end of file diff --git a/81-90/86. Partition List.js b/81-90/86. Partition List.js new file mode 100644 index 0000000..52526a7 --- /dev/null +++ b/81-90/86. Partition List.js @@ -0,0 +1,20 @@ +var partition = function(head, x) { + if(head === null) return head; + const leftDummy = new ListNode(0); + const rightDummy = new ListNode(0); + let left = leftDummy; + let right = rightDummy; + while(head){ + if(head.val < x) { + left.next = head; + left = head; + } else { + right.next = head; + right = head; + } + head = head.next; + } + right.next = null; + left.next = rightDummy.next; + return leftDummy.next; +}; \ No newline at end of file diff --git a/81-90/88. Merge Sorted Array.js b/81-90/88. Merge Sorted Array.js new file mode 100644 index 0000000..5c71551 --- /dev/null +++ b/81-90/88. Merge Sorted Array.js @@ -0,0 +1,9 @@ +var merge = function(nums1, m, nums2, n){ + nums1.length = m + nums2.length = n + let ans = nums1.concat(nums2) + ans.sort((a,b)=>a-b) + for(let i = 0 ; i < ans.length ; i++){ + nums1[i] = ans[i] + } +}; \ No newline at end of file