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 ...
随机推荐
- matlab和C/C++混合编程--Mex (六)参数传递
最近的项目需要matlab和C的混合编程,经过一番努力终于完成了项目要解决的问题.现在就将Mex的一些经验总结一下,当然只是刚刚开始,以后随着学习的深入继续添加.首先讲讲写Mex的一些常规规定,然后我 ...
- hadoop shell 操作命令
shell操作命令: hdfs的路径,在core-site.xml中定义 <property> <name>fs.default.name</name> <v ...
- 日志基本概念/rSyslog
日志是纯文本的,在var/log/ linux系统下的日志类型: 内核信息 服务信息 应用程序信息
- (spring-第9回【IoC基础篇】)BeanFactoryPostProcessor,实例化Bean之前的第二大利器
继承结构图如上.在加载XML,注册bean definition之后,在实例化bean definition之前,必要的时候要用到BeanFactoryPostProcessor.它负责把XML中有些 ...
- 关于GSMMAP分支cell_log扫描不正常问题的解决办法
阔别多年,本周在KALI 2.0下重拾旧时趣味,可怎么折腾都未曾见ARFCN,迫不得已还刷了brust_ind分支 才达到目的.后经仔细翻阅官方文档发现此问题早有披露,解决方案也已经公布,逐分享给大家 ...
- Squid Proxy Server 3.1
Improve the performance of your network using the caching and access control capabilitiess of squid. ...
- Windows 2003 AD升级Windows 2008
把Windows 2008 R2的光盘放到主域控中,运行 adprep32 /forestPrep adprep32 /domainprep adprep32 /domainprep /gpprep ...
- PHP访问REST API上传文件的解决方案
最近写的一个小功能需要通过rest方式上传文件,因此就在网上找了一些解决方案.接下来说明以下我采用的解决方案:我是利用curl来实现的,其中CURLOPT_POST的值为TRUE代表的是请求类型为PO ...
- 在Web.config中注册自定义控件
之前都是在每个页面的顶端注册用户控件或者是自定义控件,这样不简洁,而且麻烦. 现在只要在在web.config文件中声明,其他地方就可以直接使用前缀加控件如下黄色代码所示: <configura ...
- magento中某个商店实现部分样式
在magento的某个website中,已经有一个storeview A,现在要求在这个website下再创建一个新的storeview B,现在要求对于storeview B只有主页和分类页应用新的 ...