Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one operation.

Steve’s task is to delete as many characters as possible using this method and print the resulting string. If the final string is empty, print Empty String

aaabccddd → abccddd → abddd → abd
aa → Empty String

baab → bb → Empty String

string superReducedString(string s) {
for(int i=0;i<s.size()-1;)
{
  if(s.size()==0)
   { return "Empty String";}
  if(s[i]==s[i+1])
  {
    s.erase(i,2);
    i=0;
   }
  else
  {
    i++;
   }
}
return s;

superReducedString-hankerrank的更多相关文章

  1. [hankerrank]Counter game

    https://www.hackerrank.com/contests/w8/challenges/counter-game 关键是二分查找等于或最接近的小于target的数.可以使用和mid+1判断 ...

  2. Largest Rectangular Area in a Histogram 最大连续面积

    在HankerRank遇到一题计算柱状图连续矩形面积的问题. 举例 hist = [3, 2, 3]. 在这个柱状图里面最大可以容纳一个high = 2 length = 3的连续矩形, 其面积 = ...

随机推荐

  1. linux 迁移项目ProtocolException

    背景:服务器跟换机房,虚拟机完整迁移项目,只修改ip和主机名 1.检查/etc/hosts 中ip 和主机名映射 2.检查网络端口是否有限制以及端口开放是否全了,检查ip有没有配对.RMI注册不上.

  2. linux创建新用户,可以使用sudo无密码操作

    useradd -d /home/aiuap -m aiuappasswd aiuapXXXXXXXgroupadd aiuapchown -R aiuap:aiuap /home/aiuap chm ...

  3. 解决tomcat内存溢出,java.lang.OutOfMemoryError: PermGen space

    一.通过eclipse启动tomcat. 1.选择window>>preferences 2.搜索tomcat,找到自己安装的tomcat版本对应的JDK,在Optional Java V ...

  4. 对弈win32笔记

    对弈的win32笔记   一:Windows程序运行原理 一.Windows四大模块程序 1.1控制台程序 没有自己的窗口,dos-显示或者运行程序,入口mian() 1.2窗口程序 有自己的窗口,w ...

  5. 验证GridControl Gridview 单元格。

    一般的验证方法,使用单元格值改变事件.现在记录另一个事件实现验证. 场景:控制当某个单元格的值的长度不能超过10 直接看代码: private void gridViewFileContent_Val ...

  6. js之 单例模式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. linux介绍、命令(基本命令、常用命令、使用方法、基本格式)

    操作系统(科普章节) 目标 了解操作系统及作用 1. 操作系统(Operation System,OS) 一个例子说明操作系统 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如 ...

  8. ListBox多列显示,原来比较简单

    数据库的表中,如果有多个列要现实,而对应的是ListBox控件,一般情况下,ListBox是单列显示的, 例如 ListBox1.DataSource = dbcenter.accessGetData ...

  9. OpenGL的一些名词

    搬运自:https://learnopengl-cn.github.io/01%20Getting%20started/10%20Review/ 词汇表 OpenGL: 一个定义了函数布局和输出的图形 ...

  10. 用powermock 方法中new对象

    在单元测试中有时需要对方法体内new出来的对象进行方法隔离,powermock提供了这个功能,下面是一个段样例代码: UserBean user = mock(UserBean.class, RETU ...