码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2696. Minimum String Length Afte


    You are given a string s consisting only of uppercase English letters.

    You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s.

    Return the minimum possible length of the resulting string that you can obtain.

    Note that the string concatenates after removing the substring and could produce new "AB" or "CD" substrings.

    Example 1:

    Input: s = "ABFCACDB"
    Output: 2
    Explanation: We can do the following operations:
    - Remove the substring "ABFCACDB", so s = "FCACDB".
    - Remove the substring "FCACDB", so s = "FCAB".
    - Remove the substring "FCAB", so s = "FC".
    So the resulting length of the string is 2.
    It can be shown that it is the minimum length that we can obtain.

    Example 2:

    Input: s = "ACBBD"
    Output: 5
    Explanation: We cannot do any operations on the string so the length remains the same.
    

    Constraints:

    • 1 <= s.length <= 100
    • s consists only of uppercase English letters.
    1. class Solution {
    2. public:
    3. int minLength(string s) {
    4. vector<int>st;
    5. for(char ch:s){
    6. st.push_back(ch);
    7. int m=st.size();
    8. if(m>=2 &&
    9. ((st[m-1]=='B' && st[m-2]=='A') ||
    10. (st[m-1]=='D' && st[m-2]=='C'))){
    11. st.pop_back();
    12. st.pop_back();
    13. }
    14. }
    15. return st.size();
    16. }
    17. };

  • 相关阅读:
    面试题--SpringBoot
    c++(五)
    WPSpell将拼写检查添加到VCL应用程序
    视频孪生智慧水利的十大场景应用案例
    深入理解Java虚拟机(第3版)学习笔记——虚拟机字节码执行引擎(超详细)
    完美解决Echarts X坐标轴下方文字最后一个字体加粗颜色加深的问题
    电动变焦镜头的控制
    一文让你彻底掌握【Python中的filter函数】
    关于flink重新提交任务,重复消费kafka的坑
    java计算机毕业设计springboot+vue村委会管理系统
  • 原文地址:https://blog.csdn.net/2301_80161204/article/details/139407875
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号