leetcode每日一题 806. 写字符串需要的行数

leetcode每日一题 806. 写字符串需要的行数

class Solution {
  public int[] numberOfLines(int[] widths, String s) {
      int[] result = new int[2];
      result[0] = 1;
      char[] arr = s.toCharArray();
      for (char c : arr) {
          if((result[1] += widths[c-'a']) > 100){
              result[0]++;
              result[1] = widths[c-'a'];
          }
      }
      return result;
  }
}

 

 

posted @ 2022-04-12 10:09  java架构师1  阅读(33)  评论(0)    收藏  举报