電影院的座點陣圖一排一個字串,. 是空座,x 有人了。你們一共 need 個人,想坐在同一排(不用挨著)。寫 RowForFriends(rows, need),返回第一個空座夠的是第幾排(從 1 數);都不夠返回 0。
RowForFriends([]string{"xx.x", "..x.", "...."}, 3)→2RowForFriends([]string{"xxx", "x.x"}, 2)→0func RowForFriends(rows []string, need int) intpackage main
func RowForFriends(rows []string, need int) int {
for i, row := range rows {
free := 0
// 在這裡寫:range 這一排的每個座位,是 '.' 就讓 free 加 1
// 在這裡寫:空座夠了,就返回這是第幾排
}
return 0
}
寫好了先點「執行」試試示例,沒問題再點「提交」。