add new solutions
This commit is contained in:
parent
f297e11859
commit
4720cbefc4
8 changed files with 290 additions and 0 deletions
25
solutions/36/q3612/solution.go
Normal file
25
solutions/36/q3612/solution.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Package q3612 implements a solution for https://leetcode.com/problems/process-string-with-special-operations-i/
|
||||
package q3612
|
||||
|
||||
import "slices"
|
||||
|
||||
func processStr(s string) string {
|
||||
ret := make([]byte, 0, len(s)*2)
|
||||
|
||||
for i := range len(s) {
|
||||
switch s[i] {
|
||||
case '*':
|
||||
ret = ret[:max(len(ret)-1, 0)]
|
||||
case '#':
|
||||
ret = append(ret, ret...)
|
||||
case '%':
|
||||
slices.Reverse(ret)
|
||||
default:
|
||||
ret = append(ret, s[i])
|
||||
}
|
||||
}
|
||||
|
||||
return string(ret)
|
||||
}
|
||||
|
||||
var _ = processStr
|
||||
Loading…
Add table
Add a link
Reference in a new issue