add new solutions
This commit is contained in:
parent
67cad91898
commit
eb6ffe8114
24 changed files with 933 additions and 14 deletions
21
solutions/14/q1441/solution.go
Normal file
21
solutions/14/q1441/solution.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package q1441
|
||||
|
||||
const (
|
||||
PUSH = "Push"
|
||||
POP = "Pop"
|
||||
)
|
||||
|
||||
func buildArray(target []int, n int) []string {
|
||||
ret := []string{}
|
||||
last := 0
|
||||
for _, num := range target {
|
||||
for range num - last - 1 {
|
||||
ret = append(ret, PUSH, POP)
|
||||
}
|
||||
ret = append(ret, PUSH)
|
||||
last = num
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
var _ = buildArray
|
||||
18
solutions/14/q1475/solution.go
Normal file
18
solutions/14/q1475/solution.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package q1475
|
||||
|
||||
func finalPrices(prices []int) []int {
|
||||
st := make([]int, 0, 1024)
|
||||
|
||||
for i := len(prices) - 1; i >= 0; i-- {
|
||||
p := prices[i]
|
||||
for ; len(st) > 0 && st[len(st)-1] > p; st = st[:len(st)-1] {
|
||||
}
|
||||
if len(st) > 0 {
|
||||
prices[i] = p - st[len(st)-1]
|
||||
}
|
||||
st = append(st, p)
|
||||
}
|
||||
return prices
|
||||
}
|
||||
|
||||
var _ = finalPrices
|
||||
Loading…
Add table
Add a link
Reference in a new issue