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. java算法02 - 树

    树是一类重要的非线性结构.而二叉树是一种比较重要的树,接下来我们来了解二叉树的相关内容. 二叉搜索树:每个节点都不比它左子树的任意元素小,而且不比它的右子树的任意元素大. /** * 二叉搜索树 O( ...

  2. Python之元组方法

    def count(self, value): # 计算元素出现的个数 """ T.count(value) -> integer -- return number ...

  3. L1-062 幸运彩票

    彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的.本题就请你判断给定的彩票是不是幸运的. 输入格式: 输入在第一行中给出一个正整数 N(≤ 10 ...

  4. Async CallBack promise fetch

    Callback (回调函数) 在计算机程序设计中,回调函数,或简称回调(Callback 即call then back 被主函数调用运算后会返回主函数),是指通过函数参数传递到其它代码的,某一块可 ...

  5. java上传图片

    -- jsp 一定要加上enctype="multipart/form-data" method="post"  不加无法辨别是否是上传表单的数据 <fo ...

  6. 第十二周翻译-《Pro SQL Server Internals, 2nd edition》

    <Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 专业SQL服务器内部 了解在引擎盖下发生 ...

  7. electron-vue初始桌面应用

    1.安装vue-cli脚手架 npm install -g vue-cli 2.创建项目:vue init simulatedgreg/electron-vue my-project 3.安装依赖 : ...

  8. 使用TkbmMWThreadList实现线程安全列表

    2008年的2.90.00版本,作者实现了TkbmMWThreadList,之后在kbmMW 4.40.00版本,作者将TkbmMWThreadList改成了泛型版本,用以实现线程安全的列表.要使用T ...

  9. TP5 model层 返回的对象转数组

    打开 database.php 增加或修改参数'resultset_type' => '\think\Collection',即可连贯操作 model('user')->select()- ...

  10. java实现截图功能

    package Jietu; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import j ...