10000 update 10 oct · khemssharma/leetcode@9b45f8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b45f8c

Browse files
committed
update 10 oct
1 parent 0138ce0 commit 9b45f8c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
10000

DailyProblems.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```24/10/24. For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.
2+
3+
A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.
4+
5+
Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivalent or false otherwise```
6+
7+
var flipEquiv = function(root1, root2) {
8+
// base case
9+
if (root1 === null && root2 === null ) return true
10+
if (root1 === null || root2 === null) return false
11+
if (root1.val !== root2.val) return false;
12+
// recursively check no-flip/ flip
13+
return ( ( flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right) ) || ( flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left) ) )
14+
};

array.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
// check if array is sorted (increasing) and rotated
2+
var check = function (nums) {
3+
// Simply check if the next number is greater than the current
4+
// If the array is sorted in cyclic order then the next is nums[(i+1)%nums.length]
5+
// in cyclic sorted array only 1 time the next number can not be greater/lesser than the current
6+
let countDecreasingNums = 0; // counter
7+
for (let i = 0; i < nums.length; i++) {
8+
if (nums[i] > nums[(i + 1) % nums.length]) {// iterate over nums, check and count
9+
countDecreasingNums++;
10+
}
11+
}
12+
if (countDecreasingNums > 1) {
13+
return false;
14+
}
15+
return true;
16+
};
17+
18+
// array increment by one
19+
var plusOne = function (digits) {
20+
for (let i = digits.length - 1; i >= 0; i--) {
21+
if (digits[i] < 9) {
22+
// simply add one and return digits
23+
digits[i] += 1;
24+
return digits;
25+
}
26+
// countinuosly mark digit zero if it is 9
27+
digits[i] = 0;
28+
}
29+
// if all digits are marked zero then add a one in the beginning and return digits
30+
digits.unshift(1);
31+
return digits;
32+
};
33+
134
// remove duplicates in nums
235
var removeDuplicates = function (nums) {
336
let k = 0;

0 commit comments

Comments
 (0)
0