龙熠的技术小站

Leetcode 344 Reverse String

逆转字符串


题目

1
2
3
描述
Write a function that takes a string as input and returns the string reversed.
1
2
3
例子
Given s = "hello", return "olleh".

解题思路

经典题型,传统接法

解题

Language : swift

1
2
3
4
5
6
7
8
9
class Solution {
func reverseString(_ s: String) -> String {
var inReverse = ""
for letter in s.characters {
inReverse = "\(letter)" + inReverse
}
return inReverse
}
}
分享