Skip to content

Commit 2420912

Browse files
committed
Remove alternative solutions
1 parent 9ace233 commit 2420912

File tree

654 files changed

+21
-34070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

654 files changed

+21
-34070
lines changed

100-same-tree.js

-20
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,3 @@ const isSameTree = function(p, q) {
1717
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
1818
};
1919

20-
// another
21-
22-
/**
23-
* Definition for a binary tree node.
24-
* function TreeNode(val, left, right) {
25-
* this.val = (val===undefined ? 0 : val)
26-
* this.left = (left===undefined ? null : left)
27-
* this.right = (right===undefined ? null : right)
28-
* }
29-
*/
30-
/**
31-
* @param {TreeNode} p
32-
* @param {TreeNode} q
33-
* @return {boolean}
34-
*/
35-
const isSameTree = function(p, q) {
36-
if(p == null || q == null) return p === q
37-
if(p.val !== q.val) return false
38-
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
39-
};

1009-complement-of-base-10-integer.js

-27
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,3 @@ const bitwiseComplement = function (N) {
1515
return bitmask ^ N
1616
}
1717

18-
// another
19-
20-
/**
21-
* @param {number} N
22-
* @return {number}
23-
*/
24-
const bitwiseComplement = function (N) {
25-
let X = 1;
26-
while (N > X) X = X * 2 + 1;
27-
return N ^ X;
28-
}
29-
30-
// another
31-
32-
/**
33-
* @param {number} N
34-
* @return {number}
35-
*/
36-
const bitwiseComplement = function (N) {
37-
if (N === 0) return 1
38-
// l is a length of N in binary representation
39-
const l = Math.floor(Math.log(N) / Math.log(2)) + 1
40-
// bitmask has the same length as num and contains only ones 1...1
41-
const bitmask = (1 << l) - 1
42-
// flip all bits
43-
return bitmask ^ N
44-
}

1017-convert-to-base-2.js

-15
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,3 @@ function negBase(val, base) {
2121
return result;
2222
}
2323

24-
// another
25-
26-
/**
27-
* @param {number} N
28-
* @return {string}
29-
*/
30-
const baseNeg2 = function(N) {
31-
if (N === 0) return "0";
32-
let res = ''
33-
while(N !== 0) {
34-
res = (N & 1) + res
35-
N = -(N >> 1)
36-
}
37-
return res;
38-
};

1021-best-sightseeing-pair.js

-17
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,3 @@ const maxScoreSightseeingPair = function(A) {
1212
};
1313

1414

15-
// another
16-
17-
/**
18-
* @param {number[]} A
19-
* @return {number}
20-
*/
21-
const maxScoreSightseeingPair = function(A) {
22-
let ans =A[0];
23-
let prevBestIdx =0;
24-
for(let j=1;j<A.length;j++){
25-
ans = Math.max(ans, A[prevBestIdx]+prevBestIdx+A[j]-j);
26-
if(A[prevBestIdx ]+prevBestIdx <A[j]+j){
27-
prevBestIdx =j;
28-
}
29-
}
30-
return ans;
31-
};

1024-video-stitching.js

-40
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,3 @@ const videoStitching = function (clips, T) {
2424
return -1
2525
}
2626

27-
// another
28-
29-
/**
30-
* @param {number[][]} clips
31-
* @param {number} T
32-
* @return {number}
33-
*/
34-
const videoStitching = function (clips, T) {
35-
clips.sort((a, b) => a[0] - b[0])
36-
let res = 0
37-
for(let i = 0, start = 0, end = 0, len = clips.length; start < T; start = end, res++) {
38-
for(; i < len && clips[i][0] <= start; i++) {
39-
end = Math.max(end, clips[i][1])
40-
}
41-
if(start === end) return -1
42-
}
43-
return res
44-
}
45-
46-
47-
// another
48-
49-
/**
50-
* @param {number[][]} clips
51-
* @param {number} T
52-
* @return {number}
53-
*/
54-
const videoStitching = function (clips, T) {
55-
const dp = Array(T + 1).fill( T + 1 )
56-
dp[0] = 0
57-
for(let i = 0; i <= T; i++) {
58-
for(let c of clips) {
59-
if(i >= c[0] && i <= c[1]) dp[i] = Math.min(dp[i], dp[c[0]] + 1)
60-
}
61-
if(dp[i] === T + 1) return -1
62-
}
63-
return dp[T]
64-
}
65-
66-

1029-two-city-scheduling.js

-42
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,3 @@ const twoCitySchedCost = function(costs) {
2222
return dp[N][N]
2323
}
2424

25-
// another
26-
27-
/**
28-
* @param {number[][]} costs
29-
* @return {number}
30-
*/
31-
const twoCitySchedCost = function(costs) {
32-
const N = costs.length
33-
let res = 0
34-
const refund = []
35-
for(let i = 0; i < N; i++) {
36-
refund[i] = costs[i][1] - costs[i][0]
37-
res += costs[i][0]
38-
}
39-
refund.sort((a, b) => a - b)
40-
for(let i = 0; i < N / 2; i++) {
41-
res += refund[i]
42-
}
43-
return res
44-
};
45-
46-
// another
47-
48-
/**
49-
* @param {number[][]} costs
50-
* @return {number}
51-
*/
52-
const twoCitySchedCost = function(costs) {
53-
const len = costs.length
54-
if(len === 0) return 0
55-
const N = len / 2
56-
costs.sort((a, b) => (a[0] - a[1]) - (b[0] - b[1]))
57-
let res = 0
58-
for(let i = 0; i < costs.length; i++) {
59-
if(i < N) {
60-
res += costs[i][0]
61-
} else {
62-
res += costs[i][1]
63-
}
64-
}
65-
return res
66-
};

103-binary-tree-zigzag-level-order-traversal.js

-67
Original file line numberDiff line numberDiff line change
@@ -39,70 +39,3 @@ function bfs(row, res) {
3939
bfs(next, res)
4040
}
4141

42-
// another
43-
44-
/**
45-
* Definition for a binary tree node.
46-
* function TreeNode(val, left, right) {
47-
* this.val = (val===undefined ? 0 : val)
48-
* this.left = (left===undefined ? null : left)
49-
* this.right = (right===undefined ? null : right)
50-
* }
51-
*/
52-
/**
53-
* @param {TreeNode} root
54-
* @return {number[][]}
55-
*/
56-
const zigzagLevelOrder = function (root) {
57-
if (!root) return [];
58-
const queue = [root];
59-
const zigzag = [];
60-
let numLevels = 1;
61-
while (queue.length > 0) {
62-
const width = queue.length;
63-
const levelTraversal = [];
64-
for (let i = 0; i < width; i++) {
65-
const currentNode = queue.shift();
66-
if (currentNode.right) queue.push(currentNode.right);
67-
if (currentNode.left) queue.push(currentNode.left);
68-
numLevels % 2 === 0
69-
? levelTraversal.push(currentNode.val)
70-
: levelTraversal.unshift(currentNode.val);
71-
}
72-
zigzag.push(levelTraversal);
73-
numLevels++;
74-
}
75-
76-
return zigzag;
77-
};
78-
79-
// another
80-
81-
/**
82-
* Definition for a binary tree node.
83-
* function TreeNode(val, left, right) {
84-
* this.val = (val===undefined ? 0 : val)
85-
* this.left = (left===undefined ? null : left)
86-
* this.right = (right===undefined ? null : right)
87-
* }
88-
*/
89-
/**
90-
* @param {TreeNode} root
91-
* @return {number[][]}
92-
*/
93-
const zigzagLevelOrder = function (root) {
94-
const res = []
95-
dfs(root, res, 0)
96-
return res
97-
98-
function dfs(node, res, level) {
99-
if(node == null) return
100-
if(res.length <= level) res.push([])
101-
const tmp = res[level]
102-
if(level % 2 === 0) tmp.push(node.val)
103-
else tmp.unshift(node.val)
104-
105-
dfs(node.left, res, level + 1)
106-
dfs(node.right, res, level + 1)
107-
}
108-
};

1031-maximum-sum-of-two-non-overlapping-subarrays.js

-24
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,3 @@ const maxSumTwoNoOverlap = function(A, L, M) {
1717
return res
1818
}
1919

20-
// another
21-
22-
const maxSumTwoNoOverlap = function(A, L, M) {
23-
let n = A.length
24-
let sum = []
25-
sum[0] = 0
26-
for (let i = 0; i < n; i++) sum[i + 1] = sum[i] + A[i]
27-
28-
let ans = 0
29-
for (let i = L - 1; i + M < n; ++i) {
30-
for (let j = i + 1; j + M - 1 < n; ++j) {
31-
ans = Math.max(ans, sum[i + 1] - sum[i - L + 1] + sum[j + M] - sum[j])
32-
}
33-
}
34-
let tmp = L
35-
L = M
36-
M = tmp
37-
for (let i = L - 1; i + M < n; ++i) {
38-
for (let j = i + 1; j + M - 1 < n; ++j) {
39-
ans = Math.max(ans, sum[i + 1] - sum[i - L + 1] + sum[j + M] - sum[j])
40-
}
41-
}
42-
return ans
43-
}

1035-uncrossed-lines.js

-20
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,3 @@ const maxUncrossedLines = function(A, B) {
2020
};
2121

2222

23-
// another
24-
25-
const maxUncrossedLines = function(A, B) {
26-
const m = A.length,
27-
n = B.length
28-
const dp = new Array(n + 1).fill(0)
29-
let prev
30-
31-
for (let i = 1; i <= m; i++) {
32-
prev = dp[0]
33-
for (let j = 1; j <= n; j++) {
34-
let backup = dp[j]
35-
if (A[i - 1] == B[j - 1]) dp[j] = prev + 1
36-
else dp[j] = Math.max(dp[j], dp[j - 1])
37-
prev = backup
38-
}
39-
}
40-
41-
return dp[n]
42-
}

1036-escape-a-large-maze.js

-56
Original file line numberDiff line numberDiff line change
@@ -41,59 +41,3 @@ function dfs(blocked, i, j, m, n, visited) {
4141
return false
4242
}
4343

44-
// another
45-
46-
/**
47-
* @param {number[][]} blocked
48-
* @param {number[]} source
49-
* @param {number[]} target
50-
* @return {boolean}
51-
*/
52-
const isEscapePossible = function(blocked, source, target) {
53-
if (blocked.length < 2) {
54-
return true
55-
}
56-
// if (blocked[0][0] == 100025) {
57-
// return false
58-
// }
59-
const blockSet = new Set(
60-
blocked.map(el => {
61-
return el[0] + "," + el[1]
62-
})
63-
)
64-
let targetR, targetC, curR, curC
65-
;[targetR, targetC] = target
66-
let visited = new Set([])
67-
let DIRS = [[0, 1], [-1, 0], [0, -1], [1, 0]],
68-
queue = [source]
69-
const inBound = (r, c) => {
70-
return r >= 0 && c >= 0 && r < 1000000 && c < 1000000
71-
}
72-
let count = 0
73-
while (queue.length > 0) {
74-
count++
75-
;[curR, curC] = queue.shift()
76-
77-
if (count > 20000) {
78-
return true
79-
}
80-
for (let dir of DIRS) {
81-
const newR = curR + dir[0],
82-
newC = curC + dir[1]
83-
if (
84-
!inBound(newR, newC) ||
85-
blockSet.has(newR + "," + newC) ||
86-
visited.has(newR + "," + newC)
87-
) {
88-
continue
89-
}
90-
91-
if (newR == targetR && newC == targetC) {
92-
return true
93-
}
94-
visited.add(newR + "," + newC)
95-
queue.push([newR, newC])
96-
}
97-
}
98-
return false
99-
}

0 commit comments

Comments
 (0)