Skip to content

Commit 47d6447

Browse files
BarklimBarklim
Barklim
authored and
Barklim
committed
stack
1 parent 0f3804b commit 47d6447

12 files changed

+212
-5
lines changed

2390-removing-stars-from-a-string.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ var removeStars = function(s) {
3131
}
3232
return result.join('');
3333
};
34+
35+
// var removeStars = function(s) {
36+
// const stack = [];
37+
38+
// for (const char of s) {
39+
// char === '*' ? stack.pop(): stack.push(char)
40+
// }
41+
42+
// return stack.join('');
43+
// };

example/5.Stack/0020.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function(s) {
6+
7+
};
8+
9+
const example1 = isValid('()'); // true
10+
const example2 = isValid('()[]{}'); // true
11+
const example3 = isValid('(]'); // false
12+
const example4 = isValid('([])'); // true
13+
14+
const example5 = isValid('[]'); // true
15+
const example6 = isValid('([{}])'); // true
16+
const example7 = isValid('[(])'); // false
17+
18+
console.log(example1);
19+
console.log(example2);
20+
console.log(example3);
21+
console.log(example4);
22+
console.log(example5);
23+
console.log(example6);
24+
console.log(example7);

example/5.Stack/0022.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @param {number} n
3+
* @return {string[]}
4+
*/
5+
var generateParenthesis = function(n) {
6+
7+
};
8+
9+
const example1 = generateParenthesis(3); // ["((()))","(()())","(())()","()(())","()()()"]
10+
const example2 = generateParenthesis(1); // ["()"]

example/5.Stack/0071.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} path
3+
* @return {string}
4+
*/
5+
var simplifyPath = function(path) {
6+
7+
};
8+
9+
const example1 = isValid("/home/"); // "/home"
10+
const example2 = isValid("/home//foo/"); // "/home/foo"
11+
const example3 = isValid("/home/user/Documents/../Pictures"); // "/home/user/Pictures"
12+
const example4 = isValid("/../"); // "/"
13+
const example5 = isValid("/.../a/../b/c/../d/./"); // "/.../b/d"
14+
15+
console.log(example1);
16+
console.log(example2);
17+
console.log(example3);
18+
console.log(example4);
19+
console.log(example5);

example/5.Stack/0084.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} heights
3+
* @return {number}
4+
*/
5+
var largestRectangleArea = function(heights) {
6+
7+
};
8+
9+
const example1 = isValid([2,1,5,6,2,3]); // 10
10+
const example2 = isValid([2,4]); // 4
11+
const example3 = isValid([7,1,7,2,2,4]); // 8
12+
const example4 = isValid([1,3,7]); // 7
13+
14+
console.log(example1);
15+
console.log(example2);
16+
console.log(example3);
17+
console.log(example4);

example/5.Stack/0150.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string[]} tokens
3+
* @return {number}
4+
*/
5+
var evalRPN = function(tokens) {
6+
7+
};
8+
9+
const example1 = evalRPN(["2","1","+","3","*"]); // 9
10+
const example2 = evalRPN(["4","13","5","/","+"]); // 6
11+
const example3 = evalRPN(["10","6","9","3","+","-11","*","/","*","17","+","5","+"]); // 22
12+
13+
console.log(example1);
14+
console.log(example2);
15+
console.log(example3);

example/5.Stack/0739.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} temperatures
3+
* @return {number[]}
4+
*/
5+
var dailyTemperatures = function(temperatures) {
6+
7+
};
8+
9+
const example1 = dailyTemperatures([73,74,75,71,69,72,76,73]); // [1,1,4,2,1,1,0,0]
10+
const example2 = dailyTemperatures([30,40,50,60]); // [1,1,1,0]
11+
const example3 = dailyTemperatures([30,60,90]); // [1,1,0]
12+
const example4 = dailyTemperatures([30,38,30,36,35,40,28]); // [1,4,1,2,1,0,0]
13+
const example5 = dailyTemperatures([22,21,20]); // [0,0,0]
14+
15+
console.log(example1);
16+
console.log(example2);
17+
console.log(example3);
18+
console.log(example4);
19+
console.log(example5);

example/5.Stack/0853.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number} target
3+
* @param {number[]} position
4+
* @param {number[]} speed
5+
* @return {number}
6+
*/
7+
var carFleet = function(target, position, speed) {
8+
9+
};
10+
11+
const example1 = carFleet(12, [10,8,0,5,3], [2,4,1,1,3]); // 3
12+
const example2 = carFleet(10, [3], [3]); // 1
13+
const example3 = carFleet(100, [0,2,4], [4,2,1]); // 1
14+
const example4 = carFleet(10, [1,4], [3,2]); // 1
15+
const example5 = carFleet(10, [4,1,0,7], [2,2,1,1]); // 3
16+
17+
console.log(example1);
18+
console.log(example2);
19+
console.log(example3);
20+
console.log(example4);
21+
console.log(example5);

example/5.Stack/0933.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var RecentCounter = function() {
2+
3+
};
4+
5+
/**
6+
* @param {number} t
7+
* @return {number}
8+
*/
9+
RecentCounter.prototype.ping = function(t) {
10+
11+
};
12+
13+
var obj = new RecentCounter()
14+
var param_1 = obj.ping(1)
15+
16+
console.log(param_1); // 1
17+
console.log(obj.ping(3001)); // 2
18+
console.log(obj.ping()); // 3
19+
20+
function callPingMultipleTimes(obj, times, start = 1, step = 1) {
21+
let results = [];
22+
let t = start;
23+
24+
for (let i = 0; i < times; i++) {
25+
results.push(obj.ping(t));
26+
t += step;
27+
}
28+
29+
return results;
30+
}
31+
32+
var obj = new RecentCounter();
33+
console.log(callPingMultipleTimes(obj, 500, 1, 1000));

example/5.Stack/1047.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {string} s
3+
* @return {string}
4+
*/
5+
var removeDuplicates = function(s) {
6+
7+
};
8+
9+
const example1 = removeDuplicates('abbaca'); // "ca"
10+
const example2 = removeDuplicates('azxxzy'); // "ay"
11+
12+
console.log(example1);
13+
console.log(example2);

example/5.Stack/2390.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} s
3+
* @return {string}
4+
*/
5+
var removeStars = function(s) {
6+
const stack = [];
7+
8+
for (const char of s) {
9+
char === '*' ? stack.pop(): stack.push(char)
10+
}
11+
12+
return stack.join('');
13+
};
14+
15+
const example1 = removeStars('leet**cod*e'); // 'lecoe'
16+
const example2 = removeStars('erase*****'); // ''
17+
18+
console.log(example1);
19+
console.log(example2);

example/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Better order to solve problems
4242
904. Fruit Into Baskets
4343
0.
4444
121. Best Time to Buy and Sell Stock
45-
- 424. Longest Repeating Character Replacement
46-
- 567. Permutation in String
45+
424. Longest Repeating Character Replacement
46+
567. Permutation in String
4747
- 76. Minimum Window Substring
4848
- 239. Sliding Window Maximum
4949

@@ -62,8 +62,8 @@ Better order to solve problems
6262
0.
6363
143. Reorder List
6464
- 138. Copy List with Random Pointer
65-
- 2. Add Two Numbers
66-
- 287. Find the Duplicate Number
65+
2. Add Two Numbers
66+
287. Find the Duplicate Number
6767
- 23. Merge k Sorted Lists
6868
- 25. Reverse Nodes in k-Group
6969

@@ -85,13 +85,20 @@ Better order to solve problems
8585

8686
146. LRU Cache
8787

88-
### Stack, Queue
88+
### [Stack, Queue](https://github.com/Barklim/leetcode-javascript/tree/master/example/5.Stack)
8989

9090
20. Valid Parentheses
9191
1047. Remove All Adjacent duplicates in String
9292
2390. Removing Stars From a string
9393
71. Simplify Path
9494
933. Number of Recent Calls
95+
0.
96+
155. Min Stack
97+
150. Evaluate Reverse Polish Notation
98+
22. Generate Parentheses
99+
739. Daily Temperatures
100+
853. Car Fleet
101+
84. Largest Rectangle in Histogram
95102

96103
### Binare Tree, DFS
97104

0 commit comments

Comments
 (0)