Given a string, find the longest subsequence consisting of a single character. Example: longest("ABAACDDDBBA") should return {'D': 3}.

const str = "AABCDDBBBEA";

function longest (str) {
let max_count = , count = , max_char = null, prv_char = null; for (let current of str) {
if (current === prv_char) {
count++
} else {
count = ;
} if (count > max_count) {
max_count = count;
max_char = current;
} prv_char = current;
} return {[max_char]: max_count};
} console.log(longest(str)) // {B: 3}

[Algorithm] Coding Interview Question and Answer: Longest Consecutive Characters的更多相关文章

  1. Core Java Interview Question Answer

    This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...

  2. [LintCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...

  3. crack the coding interview

    crack the coding interview answer c++ 1.1 #ifndef __Question_1_1_h__  #define __Question_1_1_h__  #i ...

  4. 128. Longest Consecutive Sequence(leetcode)

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  5. 24. Longest Consecutive Sequence

    Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...

  6. 转:Top 10 Algorithms for Coding Interview

    The following are top 10 algorithms related concepts in coding interview. I will try to illustrate t ...

  7. Longest Consecutive Sequence 解答

    Question Given an unsorted array of integers, find the length of the longest consecutive elements se ...

  8. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  9. LeetCode——Longest Consecutive Sequence

    LeetCode--Longest Consecutive Sequence Question Given an unsorted array of integers, find the length ...

随机推荐

  1. 洛谷P1345 [USACO5.4]奶牛的电信 [最小割]

    题目传送门 奶牛的电信 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,..., ...

  2. FastReport.Net使用:[26]数字格式

    1.数据包含固定格式的小数,自由格式的小数,以及字符串格式等四列数据.包含3行数据(1.2,1.23,1.234). 以下为Access数据视图和FastReport.Net报表设计器中的数据视图. ...

  3. FastReport.Net使用:[5]主从表

    主从报表在日常生活中也很常用,譬如订单,班级学生报表等.下面以学生选课为例,以学生为主表,选课为从表做一学生选课报表. 绘制简单主从报表 1.绘制报表标题. 2.为数据区添加从表. ●可以直接右键数据 ...

  4. WEB架构师成长之路 一

    一 .你必须学习面向对象的基础知识 1.降低软件开发的复杂度 2.提高软件开发的效率 3.提高软件质量:可维护性,可扩展性,可重用性等. 提高软件质量:可维护性,可扩展性,可重用性等,再具体点,就是高 ...

  5. nginx fastcgi_buffers to an upstream response is buffered to a temporary file

    fastcgi_buffers 16 16k; 指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答,如上所示,如果一个php脚本所产生的页面大小为256k,则会为其分配16个16k的缓冲区来缓 ...

  6. Android消息机制——Handler

      /**android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个MessageQueue(消息队列), * 但是MessageQueue被封装到Looper里 ...

  7. SilverLight学习笔记--使用WebClient实现通讯(一)(上传和下载字符串数据)

    一.什么是WebClient类   1.基本知识    WebClient类是Mircsoft在.NET框架下提供的向 URI 标识的资源发送数据和从 URI 标识的资源接收数据的公共方法.通过这个类 ...

  8. div中内容超出自动换行

    下面以table中td的内容超出为例说明: 首先: td { display: block; } 然后:给td设置css样式: 1.  td { word-wrap: break-word; } 2. ...

  9. Tasker 中文版(4.6u2)

    http://www.anzhi.com/soft_1868913.html Tasker绝对称得上是Android系统的神器之一,与Auto Memory Manager不同,Tasker不是加速型 ...

  10. Digital variable resistor compensates voltage regulator

    A variable resistor that integrates a programmable, temperature-indexed look-up table can compensate ...