Skip to content

Commit

Permalink
806
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangshanmeta committed Nov 2, 2024
1 parent b00448b commit 8ec096b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/0806.number-of-lines-to-write-string.824/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int[] numberOfLines(int[] widths, String s) {
int row = 0;
int col = 0;
for(char c : s.toCharArray()){
int w = widths[c-'a'];
if(col+w>100){
row++;
col = w;
}else{
col += w;
}
}
return new int[]{row+1,col};
}
}

0 comments on commit 8ec096b

Please sign in to comment.