HTMLify
LeetCode - Number of Students Unable to Eat Lunch - Go
Views: 303 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | func all_same(arr []int) bool { for _, v := range arr { if v != arr[0] { return false } } return true } func countStudents(students []int, sandwiches []int) int { for ;len(students)>0; { s := students[0] if all_same(students) && s != sandwiches[0] { break } if s == sandwiches[0] { sandwiches = sandwiches[1:] students = students[1:] } else { students = append(students[1:], s) } } return len(students) } |