File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -582,6 +582,40 @@ public:
582
582
};
583
583
```
584
584
585
+ ``` go
586
+ type item struct {
587
+ n int
588
+ bytes []byte
589
+ }
590
+
591
+ func decodeString (str string ) string {
592
+ num := 0
593
+ st := []item{{1 , []byte {}}}
594
+
595
+ for i := range str {
596
+ switch {
597
+ case str[i] == ' 0' :
598
+ num *= 10
599
+ case str[i] > ' 0' && str[i] <= ' 9' :
600
+ num = num*10 + int (str[i]-' 0' )
601
+ case str[i] == ' [' :
602
+ st = append (st, item{num, []byte {}})
603
+ num = 0
604
+ case str[i] == ' ]' :
605
+ tmp := st[len (st)-1 ]
606
+ st = st[:len (st)-1 ]
607
+ for j := 0 ; j < tmp.n ; j++ {
608
+ st[len (st)-1 ].bytes = append (st[len (st)-1 ].bytes , tmp.bytes ...)
609
+ }
610
+ default :
611
+ st[len (st)-1 ].bytes = append (st[len (st)-1 ].bytes , str[i])
612
+ }
613
+ }
614
+
615
+ return string (st[0 ].bytes )
616
+ }
617
+ ```
618
+
585
619
## [ Remove K Digits] ( https://leetcode.com/problems/remove-k-digits )
586
620
587
621
A: 升序栈,仅当字符串出现降序时需要移除降序部分中较大的数字。
You can’t perform that action at this time.
0 commit comments