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

Golang | Leetcode Golang题解之第443题压缩字符串

题目:

题解:

func compress(chars []byte) int {write, left := 0, 0for read, ch := range chars {if read == len(chars)-1 || ch != chars[read+1] {chars[write] = chwrite++num := read - left + 1if num > 1 {anchor := writefor ; num > 0; num /= 10 {chars[write] = '0' + byte(num%10)write++}s := chars[anchor:write]for i, n := 0, len(s); i < n/2; i++ {s[i], s[n-1-i] = s[n-1-i], s[i]}}left = read + 1}}return write
}

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

相关文章:

  • C++ | Leetcode C++题解之第443题压缩字符串
  • Android平台如何获取CPU占用率和电池电量信息
  • C语言课程设计题目六:学生信息管理系统设计
  • 【分布式微服务云原生】10分钟打造坚不可摧的系统:深入探索系统的鲁棒性
  • 树莓派外挂Camera(基操)(TODO)
  • 全功能运营级开源跨境电商平台源码 —— 多语言全球化商城解决方案
  • systemd-analyze命令:Linux系统启动分析
  • Python库matplotlib之二
  • 【C++篇】启航——初识C++(上篇)
  • 设计模式之组合模式
  • Tomcat安装和配置教程(图文详解,最简洁易懂)
  • AI运用在营销领域的经典案例及解析
  • 深度学习反向传播-过程举例
  • 【网络安全】公钥基础设施
  • timedatectl命令:告别时间烦恼,一键同步系统时间
  • 第三节-类与对象(中)
  • 进制转换 总结
  • 深入理解 `strncat()` 函数:安全拼接字符串
  • 数据资产新范式,URP城市焕新平台东博会首发!
  • GB28181信令交互流程及Android端设备对接探讨