File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Stack {
2
+ constructor ( ) {
3
+ this . arr = [ ] ;
4
+ this . index = - 1 ;
5
+ }
6
+
7
+ push ( item ) {
8
+ this . arr [ ++ this . index ] = item ;
9
+ }
10
+
11
+ pop ( ) {
12
+ const temp = this . arr [ this . index -- ] ;
13
+ return temp ;
14
+ }
15
+
16
+ top ( ) {
17
+ return this . arr [ this . index ] ;
18
+ }
19
+ }
20
+
21
+ function solution ( s ) {
22
+ var answer = true ;
23
+
24
+ const stack = new Stack ( ) ;
25
+
26
+ for ( const char of s . split ( "" ) ) {
27
+ if ( stack . top ( ) === "(" && char === ")" ) {
28
+ stack . pop ( ) ;
29
+ } else {
30
+ stack . push ( char ) ;
31
+ }
32
+ }
33
+
34
+ return stack . index === - 1 ;
35
+ }
Original file line number Diff line number Diff line change
1
+ function solution ( arr ) {
2
+ var answer = [ ] ;
3
+
4
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
5
+ if ( arr [ i ] === answer [ answer . length === 0 ? 0 : answer . length - 1 ] ) {
6
+ continue ;
7
+ } else {
8
+ answer . push ( arr [ i ] ) ;
9
+ }
10
+ }
11
+
12
+ return answer ;
13
+ }
You can’t perform that action at this time.
0 commit comments