当前位置: 首页 > news >正文

C++ | Leetcode C++题解之第385题迷你语法分析器

题目:

题解:

class Solution {
public:NestedInteger deserialize(string s) {if (s[0] != '[') {return NestedInteger(stoi(s));}stack<NestedInteger> st;int num = 0;bool negative = false;for (int i = 0; i < s.size(); i++) {char c = s[i];if (c == '-') {negative = true;} else if (isdigit(c)) {num = num * 10 + c - '0';} else if (c == '[') {st.emplace(NestedInteger());} else if (c == ',' || c == ']') {if (isdigit(s[i - 1])) {if (negative) {num *= -1;}st.top().add(NestedInteger(num));}num = 0;negative = false;if (c == ']' && st.size() > 1) {NestedInteger ni = st.top();st.pop();st.top().add(ni);}}}return st.top();}
};
http://www.lryc.cn/news/432871.html

相关文章:

  • 【软件设计师真题】第一大题---数据流图设计
  • 系统架构的发展历程之模块化与组件化
  • 基因组学中的深度学习
  • 解决老师询问最高分数问题的编程方案
  • com.baomidou.mybatisplus.annotation.DbType 无法引入
  • 从零开始学习JVM(七)- StringTable字符串常量池
  • 数据库课程设计mysql
  • AI学习指南深度学习篇-带动量的随机梯度下降法的基本原理
  • 点餐小程序实战教程03创建应用
  • 鸿蒙自动化发布测试版本app
  • 力扣9.7
  • GPU 带宽功耗优化
  • Linux Centos 7网络配置
  • 第三天旅游线路规划
  • C++第四十七弹---深入理解异常机制:try, catch, throw全面解析
  • go 和 java 技术选型思考
  • 传统CV算法——边缘算子与图像金字塔算法介绍
  • 图像去噪算法性能比较与分析
  • Vision Transformer(ViT)模型原理及PyTorch逐行实现
  • 828华为云征文 | Flexus X实例CPU、内存及磁盘性能实测与分析
  • FreeRTOS学习笔记(六)队列
  • 【Python篇】PyQt5 超详细教程——由入门到精通(中篇一)
  • LinuxQt下的一些坑之一
  • Statement batch
  • PPP 、PPPoE 浅析和配置示例
  • 【Python机器学习】词向量推理——词向量
  • Python 语法糖:让编程更简单(续二)
  • 6 - Shell编程之sed与awk编辑器
  • 什么是XML文件,以及如何打开和转换为其他文件格式
  • 海外直播对网速、带宽、安全的要求