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. LOGISTIC REGRESSION

    In logistic regression we learn a family of functions

  2. JS 代理模式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. 关于Warn:name or service not known的解决办法

    由于之前搭建起了一个集群,然后直接将相应的配置文件复制过来 , 发现出现了 Warn:name or service not known 的问题,导致无法启动datanode. 解决的办法就是将sal ...

  4. 2013年8月份第2周51Aspx源码发布详情

    上班族网站(毕设)源码  2013-8-16 [VS2010]源码描述:自己做的毕业设计,上班族网站项目是专门针对上班族群体设计和开发的网站项目.该网站主要涵盖了论坛平台,笑话模块,名言模块,资讯模块 ...

  5. mysql 为某一数据库下所有表中添加相同字段

    BEGIN  DECLARE s_tablename VARCHAR(100);  /*显示表的数据库中的所有表 SELECT table_name FROM information_schema.t ...

  6. Android MotionEvent getX() getY() getRawX() getRawY() and View getTop() getLeft()

    getRowX:触摸点相对于屏幕的坐标getX: 触摸点相对于按钮的坐标getTop: 按钮左上角相对于父view(LinerLayout)的y坐标getLeft: 按钮左上角相对于父view(Lin ...

  7. 统计文件夹下java代码行数的小程序--主要是学习任务队列的思想

    首先感谢czbk的老师,录制的视频,让我们有这么好的学习资料.……—— 统计文件夹java文件的行数,首先想到的肯定是用递归的方法,因为文件夹下面可能包含文件夹,用递归的方法,代码容易写.(这和写简单 ...

  8. Koch曲线

    Koch曲线是一种分形,完整的Koch曲线像雪花,维基百科上记录Koch曲线最早出现在海里格·冯·科赫的论文<关于一条连续而无切线,可由初等几何构作的曲线>中,它的定义如下,给定线段AB, ...

  9. 多数求和(java)

    实验题目:从命令行接受多个数字,求和之后输出结果. 设计思想:命令行输入的字符会赋值给args数组,所以在命令行输入数字后,直接取出args的数组长度,作为循环语句的终点判断,然后利用循环将字符型改为 ...

  10. 对dataTable去重

    using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.T ...