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 ...
随机推荐
- 【活动】畅想云端加油站,赢iPad
中石化联手阿里云升级石油化工业务,已运行2月 中石化的“互联网+”战略正在不断深化.4月20日消息,中石化与阿里云共同宣布,双方将展开技术合作,借助阿里巴巴在云计算.大数据方面的技术优势,对部分传统石 ...
- 申请单位iOS开发者账号
没有AppleID的需要先申请:此处略过: 1.登录苹果开发者官网(https://developer.apple.com),网速比较慢,多试几次 2. 点击 Enroll 切换到 简体中文 我以下述 ...
- 数组多功能splice()方法的插入,删除,替换
多功能splice()插入.删除.替换 <script type="text/javascript"> var arr=['A','B','C','D','E','F' ...
- 【OBJC】数字转中文大写
博客园都不知道怎么外链图片…… - (void)numToString:(double)num{ ; NSMutableString *szChMoney = [[NSMutableString al ...
- mac apache服务器
//开启apache: sudo apachectl start //重启apache: sudo apachectl restart //关闭apache: sudo apachectl stop ...
- C# 两个结构相同的类进行赋值
假入两个类A类和B类不有任何继承关系,它们属性名相同,怎么给他们互相赋值呢?下面的方法就可以了. public L SetProperties<T, L>(T t) where L : n ...
- dctcp-ns2-patch
diff -crbB ns-allinone-2.35/ns-2.35/queue/red.cc ns-2.35/queue/red.cc *** ns-allinone--- :: --- ns-- ...
- yii2.0查询关联数据以及widgets小部件
怎样去查询关联数据呢,接下来整理一个简单的代码:
- xml-apis-ext.jar
xml-apis-ext.jar,hightcharts导出图片是解决乱码需要用到的一个包
- 在WAS控制台,环境下添加新的虚拟主机别名
错误现象: 11/16/13 16:52:22:612 CST] 00000021 util W com.ibm.ws.webcontainer.util.VirtualHostCo ...