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. left join on 后and 和 where 的区别

    SELECT * FROM student a LEFT JOIN sc b ON a.Sid = b.Sid AND a.Sname="赵雷" 结果:(left join 左连接 ...

  2. Win7下“回收站已损坏,是否清空该驱动器上的回收站”解决方法

    最近买的移动硬盘,总是不能进行安全删除,有事还会提示“回收站已损坏,是否清空该驱动器上的回收站”,可以通过下面的命令进行解决: 开始–>运行–>cmd 点确定 在cmd窗口输入rd /s ...

  3. react native进一步学习(NavigatorIOS 学习)

    特别申明:本人代码不作为任何商业的用途,只是个人学习的一些心得,为了使得后来的更多的程序员少走一些弯路.*(如若侵犯你的版权还望见谅)*. 开发工具:WebStorm,xcode 1. rn的创建的时 ...

  4. 验证GridControl Gridview 单元格。

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

  5. pycharm中连接数据库常见问题

    pymysql.err.InterfaceError: (0, '')解决办法   导致这个错误的原因是通过pymysql连接MySQL,没有关闭连接的操作,所以短时间内不会出问题,长时间保持这个连接 ...

  6. AsyncTask 进行耗时操作和UI 更新

    相信各位对 AsyncTask 不会陌生,虽然它有如下弊端: 1. 如果在activiy内部new 一个AsyncTask, 横竖屏切换生成一个新的activity,等结果返回时,处理不好容易出现NP ...

  7. P3954 成绩(noip2017普及组)

    题目描述 牛牛最近学习了C++入门课程,这门课程的总成绩计算方法是: 总成绩=作业成绩\times 20\%+×20%+小测成绩×30\%+×30%+期末考试成绩\times 50\%×50% 牛牛想 ...

  8. selenium中切换浏览器不同tab 的操作

    from selenium import webdriverimport timedriver=webdriver.Chrome()driver.get('http://ui.imdsx.cn/uit ...

  9. python爬虫基础_requests和bs4

    这些都是笔记,还缺少详细整理,后续会更新. 下面这种方式,属于入门阶段,手动成分比较多. 首先安装必要组件: pip3 install requests pip3 install beautifuls ...

  10. CentOS 6 RPM安装包下载地址

    32位系统的RPM安装包的下载地址 http://mirrors.163.com/centos/6/os/i386/Packages/ 64位系统的RPM安装包的下载地址 http://mirrors ...