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. oralce执行计划

    看懂Oracle执行计划   最近一直在跟Oracle打交道,从最初的一脸懵逼到现在的略有所知,也来总结一下自己最近所学,不定时更新ing… 一:什么是Oracle执行计划? 执行计划是一条查询语句在 ...

  2. angularjs i18n

    <!doctype html><html ng-app="myApp"><head>    <meta charset="utf ...

  3. grid-layout

    <!-- 创建三个网格布局--> .wrapper { <!--创建一个网格布局 --> display: grid; <!--创建3列 且每列都等距 --> gr ...

  4. SQL优化清单

    SQL优化清单 1.from 语句中包含多个表的情况下,把记录数少的表放在前面 2.where 语句中包含多个条件时,将刷选多的条件放前面 3.避免使用select * ,因为这样会去查询所有列的数据 ...

  5. Python条件判断 if-else for循环 while循环 break continue

    条件判断 if-else if-else语句是通过if 后面的是否为真,当为True,就执行if代码块后面的,如果为False,同时又有else语句,执行else后面的内容.没有else,什么都不执行 ...

  6. css a的伪类顺序

    a:link {color: #FF0000} /* 未访问的链接 */ a:visited {color: #00FF00} /* 已访问的链接 */ a:hover {color: #FF00FF ...

  7. Introduction to Unity UI

    https://www.raywenderlich.com/795-introduction-to-unity-ui-part-1 https://www.raywenderlich.com/794- ...

  8. vue 控制视图

    <!--第一种:点击改变容器的值--> <li> <a href="javascript:void(0)" @click="state.bo ...

  9. fiddler模拟弱网测试点

    弱网: oSession[“request-trickle-delay”] = “300”; 注释的也很明白,Delay sends by 300ms per KB uploaded.上传1KB需要3 ...

  10. matlab绘图与可视化

    1.设置图形对象属性值 set(h,'属性名称','属性值') >> subplot(,,); h1=line([ ],[ ]); text(,0.5,'unchange'); subpl ...