技术栈

Golang | Leetcode Golang题解之第557题反转字符串中的单词III

__AtYou__2024-11-13 1:06

题目:

题解:

Go 复制代码
func reverseWords(s string) string {
    length := len(s)
    ret := []byte{}
    for i := 0; i < length; {
        start := i
        for i < length && s[i] != ' ' {
            i++
        }
        for p := start; p < i; p++ {
            ret = append(ret, s[start + i - 1 - p])
        }
        for i < length && s[i] == ' ' {
            i++
            ret = append(ret, ' ')
        }
    }
    return string(ret)
}
上一篇:nodejs 020: React语法规则 props和state
下一篇:JUC学习
相关推荐
qq_51397044
21 分钟前
力扣 hot100 Day76
算法·leetcode·职场和发展
apocelipes
12 小时前
下划线字段在golang结构体中的应用
golang
一匹电信狗
1 天前
【C++】异常详解(万字解读)
服务器·c++·算法·leetcode·小程序·stl·visual studio
Python私教
1 天前
从“Hello World”到“高并发中间件”:Go 语言 2025 系统学习路线图
学习·中间件·golang
墨染点香
1 天前
LeetCode 刷题【43. 字符串相乘】
算法·leetcode·职场和发展
Keying,,,,
1 天前
力扣hot100 | 矩阵 | 73. 矩阵置零、54. 螺旋矩阵、48. 旋转图像、240. 搜索二维矩阵 II
python·算法·leetcode·矩阵
_不会dp不改名_
1 天前
leetcode_42 接雨水
算法·leetcode·职场和发展
code小毛孩
1 天前
leetcode hot100数组:缺失的第一个正数
数据结构·算法·leetcode
快去睡觉~
2 天前
力扣400:第N位数字
数据结构·算法·leetcode
热门推荐
01UV安装并设置国内源02Qwen3-Coder 快速上手教程 | Qwen Code + Claude Code03KGG转MP3工具|非KGM文件|解密音频04【2025.08.06最新版】Android Studio下载、安装及配置记录(自动下载sdk)05蜘蛛磁力 搜索引擎大全,如何使用蜘蛛磁力查找磁力链接062025最新国内服务器可用docker源仓库地址大全(2025年8月更新)07TRAE 规则(Rules)配置指南:个人习惯、团队规范与最佳实践08NVIDIA显卡驱动、CUDA、cuDNN 和 TensorRT 版本匹配指南09阿里开源首个图像生成基础模型——Qwen-Image本地部署教程,超强中文渲染能力刷新SOTA!10TRAE Rules 实践:为项目配置 6A 工作流