68. Text Justification
来源:互联网 发布:大疆无人机香港知乎 编辑:程序博客网 时间:2024/06/05 08:02
1.最后一行的处理与前面不一样
2.空格需要均匀分布
class Solution {public: vector<string> fullJustify(vector<string>& words, int maxWidth) { int n=words.size(); vector<string> ans; int i,j; int cur=0; int num=0; for(i=0;i<n;i+=num) { cur=0; num=0; int space=0; string tmp=""; for(j=i;j<n;j++) { cur+=words[j].size(); num++; if(cur+num-1>maxWidth) break; } if(cur+num-1>maxWidth) { cur-=words[j].size(); num--; } if(j>=n) { for(j=i;j<i+num-1;j++) { words[j]+=' '; tmp+=words[j]; } tmp+=words[j]; int len=tmp.size(); for(j=0;j<maxWidth-len;j++) tmp+=' '; } else { space=maxWidth-cur; while(space) { if(num==1) { words[i]+=' '; space--; } for(j=i;j<i+num-1&&space;j++) { words[j]+=' '; space--; } } for(j=i;j<i+num;j++) tmp+=words[j]; } ans.push_back(tmp); } return ans; }};
0 0
- LeetCode 68. Text Justification
- LeetCode --- 68. Text Justification
- [Leetcode] 68. Text Justification
- [leetcode] 68.Text Justification
- 68. Text Justification
- 68. Text Justification
- [leetcode] 68. Text Justification
- LeetCode 68. Text Justification
- Leetcode 68. Text Justification
- LeetCode 68. Text Justification
- 68. Text Justification
- leetcode 68. Text Justification
- 68. Text Justification
- [LeetCode] 68. Text Justification
- LeetCode-68.Text Justification
- 68. Text Justification
- leetcode 68. Text Justification
- 68. Text Justification
- HDU 5875 Function 大连网络赛 线段树
- 关于微信title无法动态改变
- 九度OJ:题目1030:毕业bg(经典背包问题)
- 制作联动下拉菜单
- ListView多选模式获取选中的项
- 68. Text Justification
- Android Support Design常用控件Snackbar,FloatingActionButton等
- RecyclerView的使用与解析
- IIS绑定域名详细教程
- 二叉查找(最简单的递归)
- 快速排序
- 1: Command Line Python(Challenge: Working with the Command Line)
- PLSQL Developer 导入中文数据出现乱码
- Android应用性能优化之分析工具