806. Number of Lines To Write String - LeetCode
生活随笔
收集整理的這篇文章主要介紹了
806. Number of Lines To Write String - LeetCode
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
Question
806. Number of Lines To Write String
Solution
思路:注意一點,如果a長度為4,當前行已經用了98個單元,要另起一行。
Java實現:
public int[] numberOfLines(int[] widths, String S) {int left = 0;int lines = 0;for (char c : S.toCharArray()) {left += widths[c - 'a'];if (left >= 100) {lines ++;left = left > 100 ? widths[c - 'a'] : 0;}}lines += left > 0 ? 1 : 0;return new int[]{lines, left}; }轉載于:https://my.oschina.net/yysue/blog/1831946
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的806. Number of Lines To Write String - LeetCode的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Thinkphp5 自定义分页类
- 下一篇: 进程间通信——POSIX 有名信号量与无