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. 洛谷P4768 [NOI2018]归程 [可持久化并查集,Dijkstra]

    题目传送门 归程 格式难调,题面就不放了. 分析: 之前同步赛的时候反正就一脸懵逼,然后场场暴力大战,现在呢,还是不会$Kruskal$重构树,于是就拿可持久化并查集做. 但是之前做可持久化并查集的时 ...

  2. MySQL 5.7 安装完成后,首次登陆的几个问题

    Server:CentOS 7.0 MySQL : 5.7.20 MySQL Community Server (GPL) 1.首次登陆后修改密码: 根据安装时的选择不同,有mysqld_safe用m ...

  3. Inno Setup Winfrom 打包工具

    1.下载并安装Inno Setup 编译器 2.安装完成后打开Inno Setup 编译器: 3.选择[用「脚本向导」创建新的脚本文件(S)]: 4.点击[下一步]: 5.填写制作后程序的基本信息: ...

  4. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  5. [NOI2011]阿狸的打字机 --- AC自动机 + 树状数组

    [NOI2011] 阿狸的打字机 题目描述: 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机. 打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母.经阿狸研究发现, ...

  6. [转]Android:布局实例之模仿QQ登录界面

    Android:布局实例之模仿QQ登录界面 预览图: 准备: 1.找到模仿对象 QQ登陆界面UI下载>>>>> 2.导入工程 3.查看布局结构和使用控件 其对应效果图分布 ...

  7. UESTC 2015dp专题 A 男神的礼物 区间dp

    男神的礼物 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descri ...

  8. JSP myecplise项目移植到ecplise

    把myecplise项目移植到ecplise的一些细节: 参考于http://www.cnblogs.com/liushuijinger/p/3396063.html 因为个人需要,需要把JSP项目从 ...

  9. PHP 基础函数(三)数组和变量之间的转换

    extract($arr);用于把数组中的元素转换成变量导入到当前文件中,键名当作变量名,值作为变量值注:(第二个参数很重要,可以看手册使用)使用方法 echo $a;compact(var1,var ...

  10. react-native-image-zoom-viewer学习

    github原地址 react-native-image-zoom-viewer实现了类似微信朋友圈浏览图片的效果,点击小图片实现浏览原图效果. 安装: npm i react-native-imag ...