电影院的座位图一排一个字符串,. 是空座,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
}
写好了先点「运行」试试示例,没问题再点「提交」。