Skip to content

147 golang fix #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions problems/problems_2353/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,31 @@ func Solve(inputJsonValues string) interface{} {
log.Println(err)
return nil
}
var foods []string
for _, vi := range opValues[0][0].([]interface{}) {
foods = append(foods, vi.(string))
var foodsArr []string
if v, ok := opValues[0][0].([]string); ok {
foodsArr = v
} else {
for _, vi := range opValues[0][0].([]interface{}) {
foodsArr = append(foodsArr, vi.(string))
}
}
var cuisines []string
for _, vi := range opValues[0][1].([]interface{}) {
cuisines = append(cuisines, vi.(string))
var cuisinesArr []string
if v, ok := opValues[0][1].([]string); ok {
cuisinesArr = v
} else {
for _, vi := range opValues[0][1].([]interface{}) {
cuisinesArr = append(cuisinesArr, vi.(string))
}
}
var arr []int
var ratingsArr []int
if v, ok := opValues[0][2].([]int); ok {
arr = v
ratingsArr = v
} else {
for _, vi := range opValues[0][2].([]interface{}) {
arr = append(arr, int(vi.(float64)))
ratingsArr = append(ratingsArr, int(vi.(float64)))
}
}
obj := Constructor(foods, cuisines, arr)
obj := Constructor(foodsArr, cuisinesArr, ratingsArr)
ans = append(ans, nil)
for i := 1; i < len(operators); i++ {
var res interface{}
Expand Down
23 changes: 14 additions & 9 deletions problems/problems_LCR_013/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (numMatrix *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) in
func Solve(inputJsonValues string) interface{} {
inputValues := strings.Split(inputJsonValues, "\n")
var operators []string
var opValues [][]interface{}
var ans []interface{}
var opValues [][]any
var ans []any
if err := json.Unmarshal([]byte(inputValues[0]), &operators); err != nil {
log.Println(err)
return nil
Expand All @@ -47,17 +47,22 @@ func Solve(inputJsonValues string) interface{} {
log.Println(err)
return nil
}
matrix := make([][]int, len(opValues[0][0].([]interface{})))
for i := range matrix {
matrix[i] = make([]int, len(opValues[0][0].([]interface{})[0].([]interface{})))
for j := range matrix[i] {
matrix[i][j] = int(opValues[0][0].([]interface{})[i].([]interface{})[j].(float64))
var matrixArr [][]int
if v, ok := opValues[0][0].([][]int); ok {
matrixArr = v
} else {
matrixArr = make([][]int, len(opValues[0][0].([]any)))
for i := range matrixArr {
matrixArr[i] = make([]int, len(opValues[0][0].([]any)[i].([]any)))
for j := range matrixArr[i] {
matrixArr[i][j] = int(opValues[0][0].([]any)[i].([]any)[j].(float64))
}
}
}
obj := Constructor(matrix)
obj := Constructor(matrixArr)
ans = append(ans, nil)
for i := 1; i < len(operators); i++ {
var res interface{}
var res any
switch operators[i] {
case "sumRegion", "SumRegion":
res = obj.SumRegion(int(opValues[i][0].(float64)), int(opValues[i][1].(float64)), int(opValues[i][2].(float64)), int(opValues[i][3].(float64)))
Expand Down
Loading