806. Number of Lines To Write String (5月24日)
解答
class Solution {
public:
vector<int> numberOfLines(vector<int>& widths, string S) {
vector<int> result;
int line=1,units=0;
map<char,int> pairs;
char c='a';
for(int width:widths){
pairs.insert(make_pair(c,width));
++c;
}
for(auto ch: S){
units += pairs[ch];
if(units > 100){
++line;
units=pairs[ch];
}
}
result.push_back(line);
result.push_back(units);
return result;
}
};
806. Number of Lines To Write String (5月24日)的更多相关文章
- 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 ...
- 806. Number of Lines To Write String - LeetCode
Question 806. Number of Lines To Write String Solution 思路:注意一点,如果a长度为4,当前行已经用了98个单元,要另起一行. Java实现: p ...
- 【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 ...
- LeetCode算法题-Number of Lines To Write String(Java实现)
这是悦乐书的第319次更新,第340篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第188题(顺位题号是806).我们要将给定字符串S的字母从左到右写成行.每行最大宽度为 ...
- [Swift]LeetCode806. 写字符串需要的行数 | 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 写字符串需要的行数
We are to write the letters of a given string S, from left to right into lines. Each line has maximu ...
随机推荐
- SQL Server中建立自定义函数
在SQL Server中用户可以自定义函数,像内置函数一样返回标量值,也可以将结果集用表格变量返回.用户自定义函数的2种类型:1.标量函数:返回一个标量值:2.表格值函数{内联表格值函数.多表格值函数 ...
- hdu 4513 吉哥系列故事——完美队形II (manachar算法)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) P ...
- Distributed TensorFlow
Distributed TensorFlow Todo list: Distributed TensorFlow简介 Distributed TensorFlow的部署与运行 对3个台主机做多卡GPU ...
- Python学习系列-----第二章 操作符与表达式
2.1 数学运算和赋值的简便方法 例如: 2.2 优先级 在python中运算符有优先级之分,高优先级的运算符先执行,低优先级的运算符后执行.下面是运算符优先级:(同一行的运算符具有相同的优先级) 2 ...
- django模板报错:Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define
转自:http://blog.csdn.net/xiaowanggedege/article/details/8651236 django模板报错: Requested setting TEMPLAT ...
- Gitlab命令行简单使用
使用Gitlab拉取远程文件到本地,然后再创建新分支的流程: git clone url #将远程分支拉取到本地: git status / git branch #查看git的状态和分支情况,g ...
- 【Leetcode】【Medium】Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- vim的visual模式
在可视化模式下,可以对一个文本块的整体进行操作.例如,首先高亮选中一部分文本,然后用d命令删除这个文本块.可视化模式的好处在于,你可以在做改动之前,就看到操作将影响的文本.可视化模式可以分为以下三种: ...
- ZT 设计模式六大原则(6):开闭原则
ZT 设计模式六大原则(6):开闭原则 分类: 设计模式 2012-02-27 08:48 24870人阅读 评论(72) 收藏 举报 设计模式扩展框架编程测试 定义:一个软件实体如类.模块和函数应该 ...
- SkyWalking 为.NET Core
SkyWalking 为.NET Core https://www.cnblogs.com/liuhaoyang/p/skywalking-dotnet-v02-release.html Apache ...