leetCode题解之Number of Lines To Write String
1、题目描述

2、分析
使用一个map将字母和数字对应起来,方便后续使用。
3、代码
vector<int> numberOfLines(vector<int>& widths, string S) {
map<char,int> m;
vector<int> ans;
for( int i = ; i< ;i++)
m[i+'a'] = widths[i];
int lines = ;
int curLen =;
int lastLen = ;
for( size_t t = ; t < S.size(); t++)
{
curLen += m[ S[t] ];
lastLen = curLen;
if(curLen > )
{
lines += ;
curLen = ;
t--;
}
}
ans.push_back(lines);
ans.push_back(lastLen);
return ans;
}
leetCode题解之Number of Lines To Write String的更多相关文章
- 【LeetCode】806. Number of Lines To Write String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用ASIIC码求长度 使用字典保存长度 日期 题目 ...
- LeetCode算法题-Number of Lines To Write String(Java实现)
这是悦乐书的第319次更新,第340篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第188题(顺位题号是806).我们要将给定字符串S的字母从左到右写成行.每行最大宽度为 ...
- LeetCode题解之Number of Segments in a String
1.题目描述 2.题目分析 找到字符串中的空格即可 3.代码 int countSegments(string s) { ){ ; } vector<string> v; ; i < ...
- 806. Number of Lines To Write String - LeetCode
Question 806. Number of Lines To Write String Solution 思路:注意一点,如果a长度为4,当前行已经用了98个单元,要另起一行. Java实现: p ...
- 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】434. Number of Segments in a String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计 正则表达式 字符串分割 日期 题目地址:htt ...
- 【LeetCode】434. Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- [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 ...
随机推荐
- Postman—authorization简介
Postman中的authorization 版权声明,参考: https://blog.csdn.net/qq_28284093/article/details/80416749 1.概述 Auth ...
- C#中null值属于什么变量类型
今天学习发现有段代码的输出结果有些理解不了,如图1,输出的结果全部为 false: 图1 后来和同事讨论研究了一下才明白,原来是这样:↓ class Program { static void Mai ...
- Virtualbox下载与安装步骤
不多说,直接上干货! 本主主要介绍一下如何从官方网站下载正版的 虚拟化 Oracle VM VirtualBox ,以及说明一下去官方下载正版软件的重要性. 一.为了系统的稳定以及数据的安全,建议下载 ...
- redis-springdata-api
使用StringRedisTempalte操作redis五种数据类型 spring-data中继承了redisTemplate, 提供redis非切片连接池 代码github地址: https://g ...
- C语言中的条件编译
通常情况,我们想让程序选择性地执行,多会使用分支语句,比如if-else 或者switch-case 等.但有些时候,可能在程序的运行过程中,某个分支根本不会执行. 比如我们要写一个跨平台项目,要求项 ...
- Linux skbuff注释笔记
SKB结构定义 /usr/src/linux/include/linux/skbuff.h sk_buff_head: struct sk_buff_head { //SKB的头结点 /* The ...
- SQL Server中使用表值函数
函数有很多限制,不能使用动态语句,不能使用临时表等等...细看一下,直接写语句就行了,不用动态语句 insert into @re select id,parid,@I from videoclass ...
- SQLServer数据库循环表操作每一条数据(游标的使用)
DECLARE @FunctionCode VARCHAR(20)--声明游标变量DECLARE curfuntioncode CURSOR FOR SELECT FunctionalityCode ...
- [日常] nginx反代websocket
去年的事 , 随便记记 ============================================================= 2017年11月6日 记录: 获取包的选择状态: d ...
- [日常] PHP设置 include_path 配置选项
动态设置php.ini中的include_path 配置选项: 两种方式set_include_path($new_include_path)ini_set('include_path',$new_i ...