Onee's Den
GithubTwitter
  • 简介
  • 项目
    • onee-framework
    • crypto-zombies
  • 博客
    • 以太坊区块数据详解
    • 区块链技术科普
    • Apollo 配置中心实战场景
      • 动态变更日志输出级别
    • JS 树形插件 jsTree 使用小记
    • MySQL 数据库的隔离级别
    • 优化 Lucene 搜索速度的一点建议
    • LeetCode 刷题之旅
      • 344. Reverse String
      • 412. Fizz Buzz
      • 461. Hamming Distance
      • 463. Island Perimeter
    • RabbitMQ 初次尝试
    • 记一次搭建 OpenVPN 过程
Powered by GitBook
On this page

Was this helpful?

  1. 博客
  2. LeetCode 刷题之旅

344. Reverse String

题目大意:输入一个字符串,返回字符串的反转,例如输入“hello”,返回“olleh”

344. Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:

Given s = "hello", return "olleh".

public String reverseString(String s) {
    char[] c = s.toCharArray();
    char temp;
    int startIndex = 0;
    int endIndex = c.length - 1;
    while (endIndex > startIndex) {
        temp = c[startIndex];
        c[startIndex] = c[endIndex];
        c[endIndex] = temp;
        startIndex ++;
        endIndex --;
    }
    return new String(c);
}
PreviousLeetCode 刷题之旅Next412. Fizz Buzz

Last updated 3 years ago

Was this helpful?