解答

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日)的更多相关文章

  1. 806. Number of Lines To Write String

    806. Number of Lines To Write String 整体思路: 先得到一个res = {a : 80 , b : 10, c : 20.....的key-value对象}(目的是 ...

  2. 【Leetcode_easy】806. Number of Lines To Write String

    problem 806. Number of Lines To Write String solution: class Solution { public: vector<int> nu ...

  3. 806. Number of Lines To Write String - LeetCode

    Question 806. Number of Lines To Write String Solution 思路:注意一点,如果a长度为4,当前行已经用了98个单元,要另起一行. Java实现: p ...

  4. 【LeetCode】806. Number of Lines To Write String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用ASIIC码求长度 使用字典保存长度 日期 题目 ...

  5. 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 ...

  6. [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 ...

  7. LeetCode算法题-Number of Lines To Write String(Java实现)

    这是悦乐书的第319次更新,第340篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第188题(顺位题号是806).我们要将给定字符串S的字母从左到右写成行.每行最大宽度为 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. 如何让div覆盖canvas元素

    第一步 请让该div和canvas同样处于同一画布,都用position:absolute; 然后设置canvas的z-index="-1",是的,你没看错 然后把要覆盖canva ...

  2. Spring 框架(三)

    1 spring l AOP :切面编程 切面:切入点 和 通知 结合 l spring aop 编程 <aop:config> 方法1: <aop:pointcut express ...

  3. jquery mobile开发中常见的问题(转载)

    1页面缩放显示问题 问题描述: 页面似乎被缩小了,屏幕太宽了. 处理方法: 在head标签内加入: <meta name="viewport" content="w ...

  4. 安装nginx及依赖包

    #!/bin/bash #auto zhangjia #date 20171007#安装SSL##################################################### ...

  5. php安装扩展redis淌过的坑

    php安装扩展redis淌过的坑 php扩展 redis cd /usr/local/src/ wget https://github.com/nicolasff/phpredis/archive/2 ...

  6. Topic model的变种及其应用[1]

    转: http://www.blogbus.com/krischow-logs/65749376.html   LDA 着实 带领着 Topic model 火了一把. 但是其实我们华人世界内,也不乏 ...

  7. 什么是SAP GUI的client

    我们用SAPGUI登录某个系统时,除了用户名和密码外,还要指定一个必填字段client: 这个client是什么东东? 看文档: SAP Client is the highest hierarchi ...

  8. SAP Fiori + Vue = ?

    2017年3月28日,我到国内一个SAP CRM客户那里,同他们的架构师关于二次开发的UI框架选择SAP UI5还是Vue进行了一番探讨.回到SAP研究院之后,我把这个问题扔到了公司的微信群里,引起了 ...

  9. 时间函数应用 time

    表 1. C 时间函数 function 定义 含义 返回值 精度 time() time 函数获得从 1970 年 1 月 1 日 0 点到当前的秒数,存储在time_t结构之中. time_t 秒 ...

  10. Tomcat的webapps目录下的classes文件夹下缺失编译好的.class文件原因及其解决方法

    右键,选择BuildPath: 可以编辑Output folder,指定编译后的文件的存放目录,一般是target/classes目录