Amazon-countDuplicate
Print the count of duplicate char in a given string in same order. Ex: Input- 'abbaccdbac', Output- 'a3b3c3d1'
import java.util.LinkedHashMap;
import java.util.Map;
/*Print the count of duplicate char in a given string in same order. Ex: Input- 'abbaccdbac', Output- 'a3b3c3d1'
*
*/
public class Solution {
public static void main(String[] args) {
String s="asbvcabc";
System.out.println(new Solution().countDuplicate(s));
}
public String countDuplicate(String s){
StringBuilder strBuilder=new StringBuilder();
Map<Character, Integer> map=new LinkedHashMap<Character, Integer>();
for(int i=0; i<s.length(); i++){
if(map.containsKey(s.charAt(i))){
int value=map.get(s.charAt(i))+1;
map.put(s.charAt(i), value);
}
else{
map.put(s.charAt(i), 1);
}
}
for(Map.Entry<Character, Integer> entry: map.entrySet()){
strBuilder.append(entry.getKey());
strBuilder.append(entry.getValue());
}
String res=strBuilder.toString();
return res;
}
}
注意题意,要选用对的数据结构
Amazon-countDuplicate的更多相关文章
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(3): 抓取amazon.com价格
通过上一篇随笔的处理,我们已经拿到了书的书名和ISBN码.(网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息 ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息及ISBN码
这一篇首先从allitebooks.com里抓取书籍列表的书籍信息和每本书对应的ISBN码. 一.分析需求和网站结构 allitebooks.com这个网站的结构很简单,分页+书籍列表+书籍详情页. ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup
开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...
- Amazon Interview | Set 27
Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...
- cosbench read异常解决办法。 Unable to verify integrity of data download. Client calculated content hash didn't match hash calculated by Amazon S3. The data may be corrupt.
问题:cosbench read测试failed 报错如下 Cosbench v0.4.2.c4 against Ceph (Hammer) / radosgw / HAproxy's HTTP en ...
- [Amazon] Amazon IAP for Unity
1> 下载amazon IAP3.0 for unity plugin 2> 根据 https://developer.amazon.com/public/apis/earn/in-app ...
- Amazon评论数据的预处理代码(Positive & Negative)
Amazon评论数据的预处理代码,用于情感分析,代码改自 https://github.com/PaddlePaddle/Paddle/tree/develop/demo/quick_start/da ...
- Amazon EC2免费VPS防止超额被扣钱三大方法:流量 硬盘读写 运行时长
Amazon EC2也就是亚马逊云服务免费VPS主机服务,内存是613MB,月流量是30GB,主机空间是30GB,可以免费使用一年,又加上Amazon服务器全球多个节点CDN和本身的名气,早在2010 ...
- Amazon AWS 架设EC2服务器(datizi)fanqiang (更新手机VPN/L2TP设置)
今天用AWS在东京架设了一台服务器用来个人fanqiang.为什么用AWS呢,阿里云学生价9.9可以搭在香港,但是我的学制今年2月份在学信网上就到期了,腾讯云holy shit,我司AZURE据说员工 ...
- How to ssh to your Amazon Elastic Beanstalk instance?
Well, if it's ec2 or a digital ocean server, it would be a lot easier- you do what you normally do f ...
随机推荐
- centos虚拟机,环境配置
yum安装 yum -y install 包名(支持*) :自动选择y,全自动yum install 包名(支持*) :手动选择y or n 1.安装vim Centos默认自带VI,功能没VIM丰富 ...
- CentOS 7.0默认使用的是firewall作为防火墙。
systemctl start firewalld.service#启动firewallsystemctl stop firewalld.service#停止firewallsystemctl dis ...
- declare 关键字在Oracle中的应用。
一般用在trigger或匿名存储过程中使用.如 declare a number;begina:=1;end;
- 2016-1-6第一个完整APP 私人通讯录的实现 2:增加提示用户的提示框,监听文本框
一:在登录时弹出提示用户的提示框: 1.使用第三方框架. 2.在登陆按钮点击事件中增加如下代码: - (IBAction)loginBtnClicked { NSString *acount = se ...
- 5分钟学习maven
英文原地址:http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 一.前提 需要懂得如何在计算机上安装软件 ...
- 实现:TextView自由复制功能
源代码已经上传,链接地址:http://download.csdn.net/detail/huangyabin001/7556825 点击打开链接 package com.example.copyfr ...
- POJ 2436 二进制枚举+位运算
题意:给出n头牛的得病的种类情况,一共有m种病,要求找出最多有K种病的牛的数目: 思路:二进制枚举(得病处为1,否则为0,比如得了2 1两种病,代号就是011(十进制就是3)),首先枚举出1的个数等于 ...
- SQL调用系统存储过程整理
SQL系统存储过程用法整理: xp_cmdshell --*执行DOS各种命令,结果以文本行返回. xp_fixeddrives --*查询各磁盘/分区可用空间 xp_loginconfig --*报 ...
- XML JSON解析--基本功能
一,json的解析 json文件: {"code": "cn","cities": [{"name": " ...
- # 20145210 《Java程序设计》第02周学习总结
教材学习内容总结 本周我对教材第三章进行了学习,第三章对Java语言的语句.语法.类型.变量的定义等内容进行了比较详细的说明,相比之前的第一章和第二章,我觉得这一章还是比较好理解的,比较容易被接受.J ...