Leetcode 68. Text Justification
来源:互联网 发布:windows小马激活工具 编辑:程序博客网 时间:2024/06/13 21:30
简单贪心题
注意:
- 如果一行只有一个单词的话,那所有的空格放在单词右边。
- 尽可能地平均分配空格(题目中说了)
python代码,非常优美
class Solution(object): def fullJustify(self, words, maxWidth): """ :type words: List[str] :type maxWidth: int :rtype: List[str] """ res, cur, num_of_letters = [], [], 0 for w in words: if num_of_letters + len(w) + len(cur) > maxWidth: for i in range(maxWidth - num_of_letters): cur[i%(len(cur)-1 or 1)] += ' ' res.append(''.join(cur)) cur, num_of_letters = [], 0 cur += [w] num_of_letters += len(w) return res + [' '.join(cur).ljust(maxWidth)]
0 0
- LeetCode 68. Text Justification
- LeetCode --- 68. Text Justification
- [Leetcode] 68. Text Justification
- [leetcode] 68.Text Justification
- [leetcode] 68. Text Justification
- LeetCode 68. Text Justification
- Leetcode 68. Text Justification
- LeetCode 68. Text Justification
- leetcode 68. Text Justification
- [LeetCode] 68. Text Justification
- LeetCode-68.Text Justification
- leetcode 68. Text Justification
- leetcode-68. Text Justification
- Leetcode 68. Text Justification
- [LeetCode] 68. Text Justification
- 【LeetCode】68. Text Justification
- Leetcode 68. Text Justification
- Leetcode 68. Text Justification
- java学习--单例模式
- 306. Additive Number
- FATAL: NO bootable medium found! System halted
- greendao3.2.0的使用及升级
- 相机选择照片及拍照后使用AFNetworking图片上传(支持一张及多张上传)
- Leetcode 68. Text Justification
- 每天一个linux命令——type
- R 远程链接MySql数据库
- 通过el表达式获取服务器的相关信息
- Golang标准库探秘(一):sync 标准库
- MySQL数据库大小写敏感设置
- Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network
- mybatis mysql union all用法
- SMARTCLIENT入门教程之二