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. jsp有哪些动作作用分别是什么?

    JSP共有以下6种基本动作: jsp:include:在页面被请求的时候引入一个文件. jsp:useBean:寻找或者实例化一个JavaBean. jsp:setProperty:设置JavaBea ...

  2. Prime Number CodeForces - 359C (属于是数论)

    Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fracti ...

  3. android 捕获所有异常 未捕获的异常

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 定义一个类 继承 应用, 实现 未捕获异常处理器 uncaughtExceptionHa ...

  4. [ZROI #316] ZYB玩字符串

    Introduction 每次在一开始为空的串$S$的任意位置插入串$p$ 给出最终的$S$,求长度最短(相同时字典序最小)的串$p$ Solution: 样例出锅差评啊,让我这种直接看样例选手挂掉5 ...

  5. Codeforces Round #194 (Div. 1) A. Secrets 数学

    A. Secrets Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/A ...

  6. Unity创建asset文件的扩展编辑器

    using UnityEngine; using UnityEditor; using System.IO; public class CreateAsset : EditorWindow { pri ...

  7. CodeM资格赛2

    题目描述 组委会正在为美团点评CodeM大赛的决赛设计新赛制. 比赛有 n 个人参加(其中 n 为2的幂),每个参赛者根据资格赛和预赛.复赛的成绩,会有不同的积分.比赛采取锦标赛赛制,分轮次进行,设某 ...

  8. linux基础命令学习 (七)压缩解压

    一.tar tar主要用来压缩和解压文件 语法: tar [主选项+辅选项] 文件或者目录 主选项: c 创建新的档案文件.如果用户想备份一个目录或是一些文件,就要选择这个选项.相当于打包. x 从档 ...

  9. jquery如何判断checkbox(复选框)是否被选中(转)

    谁都知道 在html 如果一个复选框被选中 是 checked="checked". 但是我们如果用jquery alert($("#id").attr(&qu ...

  10. 如何屏蔽PHP浏览器头信息X-Powered-By

    将 php.ini 中,将 “expose_php = On” 改为 “expose_php = Off”