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. IDEA解决SVN更新冲突

    在有冲突的文件上右键-> subversion ->resolve Text Confict->merge 将代码合并.

  2. 记录前台js判断,如果为空,給议空的占位

    这个主要是根据所有的值,按顺序输出,如果没有值,就给予空的占位, //页面加载的时候获取左边和右边的所有游客id       var array_left_start = new Array();   ...

  3. LR单用户,重复操作日志

    案例:假如你想在一个脚本中,实现登录执行1次,查询执行2次,插入执行3次,怎么办?录3个脚本?每个事务分别在脚本中复制N次? 当然不用,LR早就想到了你的需求,下面让我们隆重推出Block. 位置: ...

  4. Python全栈day9习题

    本内容主要为If条件语句和while循环的相关知识. 一.使用while循环输入1 2 3 4 5 6 8 9 10 i = 1 while i < 11: if i == 7: pass el ...

  5. hadoop.docker.up.problems: Too many levels of symbolic links

    #root@c7hp:~ excp c78 "zkServer.sh start"[1] 11:49:44 [FAILURE] c78 Exited with error code ...

  6. 芯片烧录器编程AT24C02

    网上买了两款芯片烧录器,因为项目用的到.芯片以后的类型可能是IIC 接口的.就选则了一个IIC接口的AT24C02EEPROM.进行尝试.手头上没有这款芯片. 就想起自己单片机上有这款芯片.然后就开始 ...

  7. L364 Should Your Resume Be One Page or Two?

    Should Your Resume Be One Page or Two? Conventional wisdom suggests that you should keep it short: A ...

  8. vue生命周期和钩子函数

    new Vue 创建vue实例 init events & liftcycle 开始初始化 beforeCreate 组件刚被创建,组件属性计算之前,如data属性等 init injecti ...

  9. Spark笔记

    Spark基础 第一节:什么是Spark?Spark的特点和结构 1.什么是Spark? Spark是一个针对大规模数据处理的快速通用引擎. 类似MapReduce,都进行数据的处理 2.Spark的 ...

  10. JS 最简单数组去重

    ,,,,])) // 再把set转变成array console.log(newArr) // [1,2,3,4]