leetcode-418-Sentence Screen Fitting
问题
Given a rows x cols
screen and a sentence represented by a list of non-empty words, find how many times the given sentence can be fitted on the screen.
Note:
- A word cannot be split into two lines.
- The order of words in the sentence must remain unchanged.
- Two consecutive words in a line must be separated by a single space.
- Total words in the sentence won’t exceed 100.
- Length of each word is greater than 0 and won’t exceed 10.
- 1 ≤ rows, cols ≤ 20,000.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Example 3:
1 | Input: |
分析
属于那种直观上感觉有思路,但是又感觉代码写起来很费劲的题。要总结一下这类题,找到答题的技巧。
代码
1 | class Solution { |
Author: Hatton.Liu
Link: http://hattonl.github.io/2020/03/30/leetcode-418/
License: 知识共享署名-非商业性使用 4.0 国际许可协议