fengsehng

# 题目：

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

Example:
Given s = "hello", return "olleh".``````

# 思路：

• 题意：反转字符串
• 不用考虑为空的情况，这种情况sb.toString()也是null，倒叙遍历，StringBuffer相加

# 代码：

``````public class Solution {
public String reverseString(String s) {
StringBuffer sb = new StringBuffer();
int n = s.length();
for(int i = n-1;i >= 0;i--){
sb.append(s.charAt(i));
}
return sb.toString();
}
}``````

### fengsehng

[LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母

Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leo......

2017/12/14
0
0
[leetcode] Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the int......

jdflyfly
2014/06/24
0
0
150. Evaluate Reverse Polish Notation - LeetCode

Question 150. Evaluate Reverse Polish Notation Solution 是的后缀(postfix)或逆波兰(reverse Polish)记法，计算这个表达式容易想到栈，当见到一个数时就入栈，见到操作符时该运算符作用于...

yysue
2018/06/08
0
0
Leetcode日记6

（2015/11/28） LeetCode 303 Range Sum Query - Immutable：（Easy） 1）超时的算法：每次调用sumRange函数进行一次累加运算。 2）不超时的算法：改变数组的内容，存储从0下标到当前下标所有...

fxdhdu
2015/11/28
73
0
[LeetCode] Reverse String 翻转字符串

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 这道题没什么难度，直接从两头往中间走，同时交换两边的字......

2017/12/14
0
0

onedotdot
32分钟前
1
0
MVC、MVCS、MVVM、MVP、VIPER等这么多架构模式哪一个好呢？

Java干货分享

4
0

//Student类 public class Student { public void love() { System.out.println("python"); } } //Tesy类 public class Tesy { public static void main(String[] args) throws Exceptio......

2
0

1
0

linux-tao

5
0