Skip to content

Commit 1708205

Browse files
2 parents 439c23b + a18a4a0 commit 1708205

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
|104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| [js](./algorithms/maximumDepthOfBinaryTree/maximumDepthOfBinaryTree.js) |Easy|
340340
|103|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)| |Medium|
341341
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)| [js](./algorithms/binaryTreeLevelOrderTraversal/binaryTreeLevelOrderTraversal.js) |Easy|
342-
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [java](./algorithms/sysmetricTree/Solution.java) |Easy|
342+
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [java](./algorithms/sysmetricTree/Solution.java), [js](./algorithms/sysmetricTree/Solution.js) |Easy|
343343
|100|[Same Tree](https://leetcode.com/problems/same-tree/)| [java](./algorithms/sameTree/Solution.java), [js](./algorithms/sameTree/Solution.js) |Easy|
344344
|99|[Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/)| |Hard|
345345
|98|[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)| |Medium|
@@ -373,7 +373,7 @@
373373
|70|[Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)| [js](./algorithms/climbingStairs/climbingStairs.js), |Easy|
374374
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/)| |Medium|
375375
|68|[Text Justification](https://leetcode.com/problems/text-justification/)| |Hard|
376-
|67|[Add Binary](https://leetcode.com/problems/add-binary/)| [java](./algorithms/addBinary/Solution.java) |Easy|
376+
|67|[Add Binary](https://leetcode.com/problems/add-binary/)| [java](./algorithms/addBinary/Solution.java), [js](./algorithms/addBinary/Solution.js) |Easy|
377377
|66|[Plus One](https://leetcode.com/problems/plus-one/)| |Easy|
378378
|65|[Valid Number](https://leetcode.com/problems/valid-number/)| [js](./algorithms/validNumber/validNumber.js) |Easy|
379379
|64|[Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/)| |Medium|
@@ -414,7 +414,7 @@
414414
|29|[Divide Two Integers](https://leetcode.com/problems/divide-two-integers/)| |Medium|
415415
|28|[Implement strStr()](https://leetcode.com/problems/implement-strstr/)| |Easy|
416416
|27|[Remove Element](https://leetcode.com/problems/remove-element/)| [js](./algorithms/removeElement/removeElement.js) [python](./algorithms/removeElement/removeElement.python) |Easy|
417-
|26|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [java](./algorithms/removeDuplicatesFromSortedArray/Solution.java) |Easy|
417+
|26|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [java](./algorithms/removeDuplicatesFromSortedArray/Solution.java), [js](./algorithms/removeDuplicatesFromSortedArray/Solution.js) |Easy|
418418
|25|[Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/)| |Hard|
419419
|24|[Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)| [js](./algorithms/swapNodesInPairs/swapNodesInPairs.js) |Medium|
420420
|23|[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)| [js](./algorithms/mergeKSortedLists/Solution.js) |Hard|

algorithms/addBinary/Solution.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var addBinary = function (a, b) {
2+
while (a.length > b.length) b = '0' + b;
3+
while (a.length < b.length) a = '0' + a;
4+
let res = new Array(a.length);
5+
let sum = 0;
6+
let carry = 0;
7+
for (let i = a.length - 1; i >= 0; i--) {
8+
sum = Number(a[i]) + Number(b[i]) + carry
9+
if (sum >= 2) {
10+
res[i] = sum - 2;
11+
carry = 1;
12+
} else {
13+
res[i] = sum;
14+
carry = 0;
15+
}
16+
}
17+
if (carry) res.unshift(1);
18+
return res.join('');
19+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var removeDuplicates = function(nums) {
2+
let j = 0;
3+
for(let i = 1; i < nums.length; i++) {
4+
if (nums[j] !== nums[i]) {
5+
j++;
6+
nums[j] = nums[i];
7+
}
8+
}
9+
return j + 1;
10+
};

algorithms/sysmetricTree/Solution.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var isSymmetric = function(root) {
2+
if (!root) return true;
3+
4+
const isMirror = (l, r) => {
5+
if (!l && !r) return true;
6+
if (l && r && (l.val === r.val) &&
7+
isMirror(l.left, r.right) &&
8+
isMirror(l.right, r.left)
9+
) {
10+
return true;
11+
}
12+
return false;
13+
}
14+
15+
return isMirror(root.left, root.right);
16+
};

0 commit comments

Comments
 (0)