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

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

题目:

题解:

class Solution:def deserialize(self, s: str) -> NestedInteger:if s[0] != '[':return NestedInteger(int(s))stack, num, negative = [], 0, Falsefor i, c in enumerate(s):if c == '-':negative = Trueelif c.isdigit():num = num * 10 + int(c)elif c == '[':stack.append(NestedInteger())elif c in ',]':if s[i-1].isdigit():if negative:num = -numstack[-1].add(NestedInteger(num))num, negative = 0, Falseif c == ']' and len(stack) > 1:stack[-2].add(stack.pop())return stack.pop()

http://www.mrgr.cn/news/20014.html

相关文章:

  • 鸿蒙OS试题
  • ”wait”和“notify”为什么要在Synchronized代码块里面?
  • 用Python实现时间序列模型实战——Day 11: 指数平滑模型
  • matlab 计算3D点到三角面的距离
  • 【基础算法总结】BFS_拓扑排序问题
  • 模电-三极管2
  • 推荐一款开源、高效、灵活的Redis桌面管理工具:Tiny RDM!支持调试与分析功能!
  • 华为OD机试真题 - 停车场车辆统计 - 贪心算法(Java/Python/JS/C/C++ 2024 D卷 200分)
  • 【Rust光年纪】构建高效气象模型计算系统:Rust语言库推荐与比较
  • 浅聊kubernetes 调度
  • 使用Python实现智能金融市场预测
  • 读软件设计的要素01概念
  • ASTER L2 表面反射率 SWIR 和 ASTER L2 表面反射率 VNIR V003
  • 向量数据库之Milvus
  • 独孤思维:副业不要被用户牵着鼻子走
  • RPC框架-Dubbo
  • 电脑知识:如何恢复 Word、媒体和存档文件?
  • Python 中的 None 是什么,探秘 None 的多种用途
  • ssh之登录服务器自动进入目录(四十七)
  • HART转Modbus转换器