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

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

题目:

题解:

func deserialize(s string) *NestedInteger {
    index := 0
    var dfs func() *NestedInteger
    dfs = func() *NestedInteger {
        ni := &NestedInteger{}
        if s[index] == '[' {
            index++
            for s[index] != ']' {
                ni.Add(*dfs())
                if s[index] == ',' {
                    index++
                }
            }
            index++
            return ni
        }

        negative := s[index] == '-'
        if negative {
            index++
        }
        num := 0
        for ; index < len(s) && unicode.IsDigit(rune(s[index])); index++ {
            num = num*10 + int(s[index]-'0')
        }
        if negative {
            num = -num
        }
        ni.SetInteger(num)
        return ni
    }
    return dfs()
}

http://www.kler.cn/news/288645.html

相关文章:

  • Java图形用户界面之Applet设计
  • python django 使用教程
  • 使用 streamlink 把 m3u8 转为 mp4
  • 代码随想录 刷题记录-24 图论 (1)理论基础 、深搜与广搜
  • 保姆级Maven安装、配置、版本查询教程(包含配置本地仓库、阿里云私服、环境变量)
  • 射频指纹特征提取:揭秘无线通信设备的身份标识
  • 网络准入管理系统是什么?网络准入很重要,2024年国内外网络准入控制系统有哪些?(靠谱儿~)
  • filezilla使用教程(window下filezilla使用教程)
  • TF | SD 卡出现无法删除的文件,乱码文件该如何处理 macOS
  • 太速科技-基于Kintex-7 XC7K160T 的CameraLink转四路光纤数据转发卡(Full Camera Link图像转万兆以太网适配器 )
  • PostgreSQL + PostGIS:空间数据存储及管理解决方案
  • 【java入门】JDK的下载安装与配置,最新最详细教程!
  • vue3+vite+ts如何使用路由
  • pyecharts可视化数据大屏
  • 【Python】3.基础语法(3)函数
  • Python实现BASE64 算法
  • 网络安全售前入门09安全服务——安全加固服务
  • Django-debug-toolbar的作用
  • Java 入门指南:Java 并发编程 —— 单例模式
  • 在Nginx上部署前端Vue项目,超级简单!!
  • 浅谈C# 虚函数和重写
  • html+css+js网页设计 中秋节-作业1个页面
  • 使用 Pandas 进行数据可视化:全面指南(六)
  • 前端框架的演变与选择
  • 【unity实战】使用新版输入系统Input System+Rigidbody实现第三人称人物控制器(附项目源码)
  • Vue window.location详解
  • 【Linux】08.Linux 下的第一个小程序——进度条
  • 分类预测|基于鲸鱼优化WOA最小二乘支持向量机LSSVM的数据分类预测Matlab程序WOA-LSSVM 多特征输入多类别输出
  • Unity 不规则进度条显示
  • 操作系统页面置换: 最近最少使用算法(LRU)