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. java基础之 反射

    首先,我们在开始前提出一个问题: 1.在运行时,对于一个java类,能否知道属性和方法:能否去调用它的任意方法? 答案是肯定的. 本节所有目录如下: 什么是JAVA的反射机制 JDK中提供的Refle ...

  2. 未能加载文件或程序集“System.WEB.DataVisualization, Version=3.5.0.0, Culture=neutral

    项目打开 提示 如题错误. 最近用VS2010 + .NET Framework3.5SP1开发程序,使用了MsChart,但是部署到服务器的时候提示如下错误: 分析器错误消息: 未能加载文件或程序集 ...

  3. zoj1530 bfs

    //Accepted zoj1530 270ms 40008KB #include <cstdio> #include <cstring> #include <iostr ...

  4. 检测INT3 软断点

    “INT3”断点指令的机器码是 “0xcch” 检测思路,取函数地址,判断第一个字节是不是 “CCh” BYTE bFirst = ; ProcAddres = GetProcAddress(Load ...

  5. hdu 2082

    ps:get到了母函数...看了好久的模板与介绍....似懂非懂..决定要多找些题来试试... 代码: #include "stdio.h" #include "stri ...

  6. hdu 2061

    PS:  以为找个简单来恢复信心..结果碰到那么傻逼的题目... 题意:给出学分和成绩,算GPA...关键是注意换行....它要求的换行我觉得超级奇怪...除了第一个正常,其他的输入完之后先一个换行. ...

  7. ios 从网络上获取图片并在UIImageView中显示

    ios 从网络上获取图片   -(UIImage *) getImageFromURL:(NSString *)fileURL { NSLog(@"执行图片下载函数"); UIIm ...

  8. BZOJ 1584 打扫卫生

    好题! 本来想用一般的方法瞎搞个线段树什么的...发现不行... 然后翻题解. 注意到最优答案不会超过n,所以维护b[]数组,b[j]表示b[j]+1.....i有j个不同的数. 复杂度n√n. #i ...

  9. pscp使用详解 Windows与Linux文件互传工具

    pscp使用详解 Windows与Linux文件互传工具 pscp使用方法详解:pscp是putty安装包所带的远程文件传输工具,是一款十分常见windows与linux系统之间文件互传的工具,使用方 ...

  10. I.MX6 32G SD卡测试

    /*********************************************************************** * I.MX6 32G SD卡测试 * 说明: * 这 ...