aa
This commit is contained in:
@@ -218,13 +218,69 @@ func TestUpdateExpand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUploadImageNew(t *testing.T) {
|
||||
fmt.Println(spiralOrder([][]int{[]int{1, 2, 3, 4}, []int{5, 6, 7, 8}, []int{9, 10, 11, 12}}))
|
||||
fmt.Println(calculate("22+23*2/22"))
|
||||
}
|
||||
|
||||
//给定一个包含正整数、加(+)、减(-)、乘(*)、除(/)的算数表达式(括号除外),计算其结果。
|
||||
//表达式仅包含非负整数,+, - ,*,/ 四种运算符和空格 。 整数除法仅保留整数部分。
|
||||
func calculate(s string) int {
|
||||
// result := 0
|
||||
// s = strings.Trim(s, " ")
|
||||
// count := map[string]func(a, b int) int{
|
||||
// "+": func(a, b int) int {
|
||||
// return a + b
|
||||
// },
|
||||
// "-": func(a, b int) int {
|
||||
// return a - b
|
||||
// },
|
||||
// "*": func(a, b int) int {
|
||||
// return a * b
|
||||
// },
|
||||
// "/": func(a, b int) int {
|
||||
// return a / b
|
||||
// },
|
||||
// }
|
||||
// var str []string
|
||||
// mem := ""
|
||||
// for k, v := range s {
|
||||
// if _, ok := count[string(v)]; !ok {
|
||||
// mem = mem + string(v)
|
||||
// } else {
|
||||
// str = append(str, mem)
|
||||
// mem = ""
|
||||
// str = append(str, string(v))
|
||||
// }
|
||||
// if k == len(s)-1 {
|
||||
// str = append(str, mem)
|
||||
// }
|
||||
// }
|
||||
// count := func(s []string) (r []string) {
|
||||
|
||||
// return r
|
||||
// }
|
||||
|
||||
// for k, v := range str {
|
||||
// if v == "*" || v == "/" {
|
||||
// if k1, err := strconv.Atoi(str[k-1]); err == nil {
|
||||
// if k2, err := strconv.Atoi(str[k+1]); err == nil {
|
||||
// result += count[v](k1, k2)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return 1
|
||||
}
|
||||
|
||||
//输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。
|
||||
func spiralOrder(matrix [][]int) []int {
|
||||
var result []int
|
||||
|
||||
if len(matrix) == 0 {
|
||||
return result
|
||||
} else {
|
||||
if len(matrix[0]) == 0 {
|
||||
return result
|
||||
}
|
||||
}
|
||||
l, h := len(matrix[0]), len(matrix)
|
||||
left, right, top, bottom := 0, l-1, 0, h-1
|
||||
lmax, tmax := 0, 0
|
||||
@@ -241,26 +297,34 @@ func spiralOrder(matrix [][]int) []int {
|
||||
|
||||
for left <= lmax && top+1 <= tmax {
|
||||
for left1 := left; left1 <= right; left1++ {
|
||||
if len(result) >= l*h {
|
||||
break
|
||||
}
|
||||
result = append(result, matrix[top][left1])
|
||||
}
|
||||
fmt.Println(result, 1)
|
||||
if h > 1 {
|
||||
for top1 := top + 1; top1 <= bottom; top1++ {
|
||||
if len(result) >= l*h {
|
||||
break
|
||||
}
|
||||
result = append(result, matrix[top1][right])
|
||||
}
|
||||
fmt.Println(result, 2)
|
||||
if right > 0 {
|
||||
for right1 := right - 1; right1 >= left; right1-- {
|
||||
if len(result) >= l*h {
|
||||
break
|
||||
}
|
||||
result = append(result, matrix[bottom][right1])
|
||||
}
|
||||
}
|
||||
fmt.Println(result, 3)
|
||||
if bottom > 0 {
|
||||
for bottom1 := bottom - 1; bottom1 >= top+1; bottom1-- {
|
||||
if len(result) >= l*h {
|
||||
break
|
||||
}
|
||||
result = append(result, matrix[bottom1][left])
|
||||
}
|
||||
}
|
||||
fmt.Println(result, 4)
|
||||
}
|
||||
left++
|
||||
top++
|
||||
|
||||
Reference in New Issue
Block a user