算法
实现类题
每次找下一次开始的位置。
C++ 代码
def wordsTyping(self, sentence, rows, cols):
# Write your code here
words = ' '.join(sentence) + ' '
n = len(words)
position = 0
for i in range(rows):
position += cols
if words[position % n] == ' ':
position += 1
else:
while position >= 1 and words[(position - 1) % n] != ' ':
position -= 1
return position / n