Kodewick
开始学 →
小挑战←→0 / 70

和朋友看电影

#024小挑战循环字符串约 7 分钟

电影院的座位图一排一个字符串,. 是空座,x 有人了。你们一共 need 个人,想坐在同一排(不用挨着)。写 RowForFriends(rows, need),返回第一个空座够的是第几排(从 1 数);都不够返回 0。

示例
RowForFriends([]string{"xx.x", "..x.", "...."}, 3)→2
RowForFriends([]string{"xxx", "x.x"}, 2)→0
函数func RowForFriends(rows []string, need int) int
main.go
package main

func RowForFriends(rows []string, need int) int {
	for i, row := range rows {
		free := 0
		// 在这里写:range 这一排的每个座位,是 '.' 就让 free 加 1
		// 在这里写:空座够了,就返回这是第几排
	}
	return 0
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。