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 ...
随机推荐
- jquery each() 方法跳出循环
1.jquery each() 方法 return false: 的时候 相当于 break; 跳出整个循环: 2.jquery each() 方法 return true: 的时候 相当于 ...
- JAVA基本数据类型、引用数据类型-参数传递详解
1:基本类型的参数传值 对于基本数据类型,修改这个值并不会影响作为参数传进来的那个变量,因为你修改的是方法的局部变量,是一个副本.实参的精度级别应等于或低于形参的精度级别,否则报错. class JB ...
- Java中的volatile关键字的功能
Java中的volatile关键字的功能 volatile是java中的一个类型修饰符.它是被设计用来修饰被不同线程访问和修改的变量.如果不加入volatile,基本上会导致这样的结果:要么无法编写多 ...
- Detecting Client Connection in WCF Long Running Service (Heartbeat Implementation) z
Download source - 45.3 KB Introduction Hello everyone! This is my first blog on WCF and I hope that ...
- ARC以及MRC中setter方法的差异
ARC以及MRC中setter方法的差异 有时候,你会需要重写setter或者getter方法,你知道么,ARC与MRC的setter方法是有着差异的呢. 先看下MRC下的setter方法: 在看下A ...
- Elasticsearch.yml
cluster.name: elasticsearch配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集 ...
- Java集合工具类
import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map ...
- 为tcp的connect设置超时时间
struct timeval tv = {timeout, 0}; 27 setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(s ...
- ZT北大青鸟营业额超20亿到不值一提 衰落的背后
北大青鸟营业额超20亿到不值一提 衰落的背后 2013-10-18 08:18 王根旺 我要评论 (0) “北大青鸟是个悲剧!”说到曾经的IT培训业巨头,黑马导师.珍品网创始人曹允东惋惜道.在学大创 ...
- php生成csv文件并提供下载及相关注意事项
1.生成文件过程略,只要逗号分割就可以了 2.提供下载加上如下代码: header("Content-type: application/octet-stream"); heade ...