File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Algorithms
2
2
3
- ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-188 /2081-1f425f.svg )
4
- ![ problems-solved-java] ( https://img.shields.io/badge/Java-188 /2081-1abc9c.svg )
3
+ ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-189 /2081-1f425f.svg )
4
+ ![ problems-solved-java] ( https://img.shields.io/badge/Java-189 /2081-1abc9c.svg )
5
5
![ problems-solved-python] ( https://img.shields.io/badge/Python-186/2081-1abc9c.svg )
6
6
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
7
7
[ ![ cp] ( https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg )] ( https://github.com/anishLearnsToCode/competitive-programming )
217
217
| 796 | [ Rotate String] ( https://leetcode.com/problems/rotate-string ) | [ ![ Java] ( assets/java.png )] ( src/RotateString.java ) |
218
218
| 800 | [ Similar RGB Color] ( https://leetcode.com/problems/similar-rgb-color ) | |
219
219
| 804 | [ Unique Morse Code Words] ( https://leetcode.com/problems/unique-morse-code-words ) | [ ![ Java] ( assets/java.png )] ( src/UniqueMorseCodeWords.java ) |
220
- | 806 | [ Number of Lines to Write String] ( https://leetcode.com/problems/number-of-lines-to-write-string ) | |
220
+ | 806 | [ Number of Lines to Write String] ( https://leetcode.com/problems/number-of-lines-to-write-string ) | [ ![ Java ] ( assets/java.png )] ( src/NumberOfLinesToWriteInString.java ) |
221
221
| 811 | [ Subdomain Visit Count] ( https://leetcode.com/problems/subdomain-visit-count ) | |
222
222
| 812 | [ Largest Triangle Area] ( https://leetcode.com/problems/largest-triangle-area ) | |
223
223
| 819 | [ Most Common Word] ( https://leetcode.com/problems/most-common-word ) | |
Original file line number Diff line number Diff line change
1
+ public class NumberOfLinesToWriteInString {
2
+ public int [] numberOfLines (int [] widths , String string ) {
3
+ int lines = 1 , width = 0 ;
4
+ for (char character : string .toCharArray ()) {
5
+ if (width + widths [character - 'a' ] <= 100 ) {
6
+ width += widths [character - 'a' ];
7
+ } else {
8
+ lines ++;
9
+ width = widths [character - 'a' ];
10
+ }
11
+ }
12
+ return new int [] {lines , width };
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments