HTMLify

LeetCode - Number of Students Unable to Eat Lunch - Go
Views: 15 | Author: abh
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)
}

Comments