806. Number of Lines To Write String - LeetCode
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};
}
806. Number of Lines To Write String - LeetCode的更多相关文章
- 806. Number of Lines To Write String
806. Number of Lines To Write String 整体思路: 先得到一个res = {a : 80 , b : 10, c : 20.....的key-value对象}(目的是 ...
- 【Leetcode_easy】806. Number of Lines To Write String
problem 806. Number of Lines To Write String solution: class Solution { public: vector<int> nu ...
- 【LeetCode】806. Number of Lines To Write String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用ASIIC码求长度 使用字典保存长度 日期 题目 ...
- LeetCode 806 Number of Lines To Write String 解题报告
题目要求 We are to write the letters of a given string S, from left to right into lines. Each line has m ...
- [LeetCode&Python] Problem 806. Number of Lines To Write String
We are to write the letters of a given string S, from left to right into lines. Each line has maximu ...
- 806. Number of Lines To Write String (5月24日)
解答 class Solution { public: vector<int> numberOfLines(vector<int>& widths, string S) ...
- LeetCode算法题-Number of Lines To Write String(Java实现)
这是悦乐书的第319次更新,第340篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第188题(顺位题号是806).我们要将给定字符串S的字母从左到右写成行.每行最大宽度为 ...
- [LeetCode] Number of Lines To Write String 写字符串需要的行数
We are to write the letters of a given string S, from left to right into lines. Each line has maximu ...
- leetCode题解之Number of Lines To Write String
1.题目描述 2.分析 使用一个map将字母和数字对应起来,方便后续使用. 3.代码 vector<int> numberOfLines(vector<int>& wi ...
随机推荐
- C++ | 智能指针初探
智能指针初探 在 c/c++ 语言中有一种特殊的类型--指针类型. 指针作为实体,是一个用来保存一个内存地址的计算机语言中的变量.它可以直接对内存地址中的数据进行操作,是一种非常灵活的变量.指针被誉为 ...
- php实验一 html网页设计
页面展示: 源码demo: 等我传到github
- 【Android开发】富文本
SpannableString spannableString = new SpannableString("设置文字的前景色为淡蓝色"); ForegroundColorSpan ...
- 【weex开发】vue-swipe 滑动组件的使用
一,vue-swipe简介 vue-swipe 是饿了么团队开发的vue专用的轮播图插件: 可以实现简单的图片和view轮播,可控制动画时长,可限制手动滑动: 简而言之,可以实现轮播,也可以实现ppt ...
- 【Android开发】Android 颜色透明度换算
透明度 透明度分为256阶(0-255),计算机上用16进制表示为(00-ff). 透明就是0阶,不透明就是255阶,如果50%透明就是127阶(256的一半当然是128,但因为是从0开始,所以实际上 ...
- java中为什么接口中的属性都默认为static和final?
1)为什么接口中的属性都默认为static和final?Sun公司当初为什么要把java的接口设计发明成这样?[新手可忽略不影响继续学习]答:马克-to-win:接口中如果可能定义非final的变量的 ...
- No origin bean specified和 No destination bean specified
Beanutils.copyProperties 异常一: No origin bean specifiedBeanutils.copyProperties 异常二: No destination b ...
- redis的基础命令操作
文章目录 前言 一.字符串类型 二.哈希类型 三.列表类型 四.集合类型 五.有序集合类型 六.通过命令 前言 redis的数据结构 redis存储的是key,value格式的数据,其中的key是字符 ...
- conn username/password@servicename
conn username/password 方式连接的时候,会碰到这样的错误问题 oracle@prd:/home/oracle/impdir$sqlplus /nolog SQL*Plus: Re ...
- linux mysql导入导出sql文件
导出 导出单独数据库:mysqldump -uroot -p 数据库名 > 数据库名.sql 例:mysqldump -uroot -p database1 > database1.sql ...