天增的博客
首页
博客
  • 分布式解决方案
  • Java并发工具包
  • redis
  • LeetCode
  • 系统设计
  • JVM体系
Github (opens new window)
Rss (opens new window)
  • zh-CN
  • en-US
首页
博客
  • 分布式解决方案
  • Java并发工具包
  • redis
  • LeetCode
  • 系统设计
  • JVM体系
Github (opens new window)
Rss (opens new window)
  • zh-CN
  • en-US
  • LeetCode
  • 双指针
    • 26.删除有序数组中的重复项
    • 80.删除有序数组中的重复项2
    • 27.移除元素
    • 167.两数之和 II - 输入有序数组
    • 283.移动零
    • 125.验证回文串
    • 344.反转字符串
    • 11.盛最多水的容器
    • 345.反转字符串中的元音字母
  • topic
  • LeetCode
  • 双指针
  • 反转字符串
2022-05-25

344.反转字符串

# 344.反转字符串

LeetCode链接: https://leetcode.cn/problems/reverse-string/ (opens new window)

题目描述: 原地反转字符数组char[s]

输入:s = ["h","e","l","l","o"]
输出:["o","l","l","e","h"]

  • 申明左右指针,左边代表首字母,右边代表位字母
  • 首字母与倒数第一个字母交换
  • 第二个字母与倒数第二个字母交换
  • 重复以上过程,直到走到中间位置的字母为止
public void reverseString(char[] s) {
        int left = 0;
        int right = s.length - 1;
        while (left < right){
            char tmp = s[left];
            s[left] = s[right];
            s[right] = tmp;
            left++;
            right--;
        }
    }
最近更新
01
以 root 身份启动 transmission-daemon
12-13
02
Debian系统安装qbittorrent-nox
12-09
03
LXC Debain12安装zerotier并实现局域网自动nat转发
07-29
更多文章>
Theme by Vdoing | Copyright © 2015-2024 天增 | 苏ICP备16037388号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式