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的更多相关文章

  1. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(3): 抓取amazon.com价格

    通过上一篇随笔的处理,我们已经拿到了书的书名和ISBN码.(网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息 ...

  2. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息及ISBN码

    这一篇首先从allitebooks.com里抓取书籍列表的书籍信息和每本书对应的ISBN码. 一.分析需求和网站结构 allitebooks.com这个网站的结构很简单,分页+书籍列表+书籍详情页. ...

  3. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup

    开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...

  4. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

  5. 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 ...

  6. [Amazon] Amazon IAP for Unity

    1> 下载amazon IAP3.0 for unity plugin 2> 根据 https://developer.amazon.com/public/apis/earn/in-app ...

  7. Amazon评论数据的预处理代码(Positive & Negative)

    Amazon评论数据的预处理代码,用于情感分析,代码改自 https://github.com/PaddlePaddle/Paddle/tree/develop/demo/quick_start/da ...

  8. Amazon EC2免费VPS防止超额被扣钱三大方法:流量 硬盘读写 运行时长

    Amazon EC2也就是亚马逊云服务免费VPS主机服务,内存是613MB,月流量是30GB,主机空间是30GB,可以免费使用一年,又加上Amazon服务器全球多个节点CDN和本身的名气,早在2010 ...

  9. Amazon AWS 架设EC2服务器(datizi)fanqiang (更新手机VPN/L2TP设置)

    今天用AWS在东京架设了一台服务器用来个人fanqiang.为什么用AWS呢,阿里云学生价9.9可以搭在香港,但是我的学制今年2月份在学信网上就到期了,腾讯云holy shit,我司AZURE据说员工 ...

  10. 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 ...

随机推荐

  1. SharePoint表单和工作流 - Nintex篇(三)

    博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 跳转到网站设置的Nintex设置,我们来挨个了解一下,这里面一共有15项设置,本篇我们先了解前7个. " ...

  2. 一道面试题,简单模拟spring ioc

    自己实现的,程序写的土了点,很多情况没去考虑,主要是复习理解怎么使用反射来实现spring 的依赖注入. package dom4jtest; import java.lang.reflect.Inv ...

  3. 框架设计——MVC IOC

    主要概念: 注:以下概念是自我理解,不是很准确. IOC:Inversion of Control(控制反转). 本来对象创建是通过使用类内部进行创建,现在把对象创建交给container(容器)管理 ...

  4. 转 15款免费WiFi(入侵破解)安全测试工具

    转:http://www.ctocio.com/security/cloudsecurity/6594.html 一.Vistumbler扫描器 WiFi 扫描器能能发现附近AP的详细信息,例如信号强 ...

  5. jQuery easyui 提示框

    1:弹出提示窗的使用 (1)屏幕右下弹出提示窗口: $.messager.show({ title:'My Title', msg:'Message will be closed after 4 se ...

  6. solr学习之入门篇

    一,简介 Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过Http ...

  7. Tomcat容器运行struts2+spring+mybatis架构的java web应用程序简单分析

    1.具体的环境为 MyEclipse 8.5以及自带的tomcat spring3.0.5 struts2.3.15.1 mybatis3.0.5 2.想弄明白的一些问题 tomcat集成spring ...

  8. Windows系统下安装Beautiful Soup4的步骤和方法

    1.到http://www.crummy.com/software/BeautifulSoup/网站上下载,最新版本是4.3.2. 2.下载完成之后需要解压缩,假设放到D:\Python27下. 3. ...

  9. .NET的语法优化

    1.多参数 判断 条件 //判断 var fileKey = new { DateStart = search.DateStart.IsNull(), //关开始时间 DateEnd = search ...

  10. iOS9的适配

    1.大部分社交平台接口不支持https协议. 问题描述:在iOS9下,系统默认会拦截对http协议接口的访问,因此无法获取http协议接口的数据.对ShareSDK来说,具体表现可能是,无法授权.分享 ...