15算法课程 344. Reverse String
2017-12-22 23:29
344 查看
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
solution:
字符串反转
code:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
solution:
字符串反转
code:
class Solution { public: string reverseString(string s) { int left=0, right=s.length()-1; while(left<right) { swap(s[left], s[right]); left++, right--; } return s; } };
相关文章推荐
- 15算法课程 66. Plus One
- 15算法课程 104. Maximum Depth of Binary Tree
- 15算法课程 303. Range Sum Query - Immutable
- 15算法课程 191. Number of 1 Bits
- 15算法课程 67. Add Binary
- 15算法课程 235. Lowest Common Ancestor of a Binary Search Tree
- 15算法课程 326. Power of Three
- 15算法课程 204. Count Primes
- 15算法课程 237. Delete Node in a Linked List
- 15算法课程 136. Single Number
- 15算法课程 342. Power of Four
- 15算法课程 20. Valid Parentheses
- 15算法课程 205. Isomorphic Strings
- 15算法课程 202. Happy Number
- 15算法课程 107. Binary Tree Level Order Traversal II
- 15算法课程 219. Contains Duplicate II
- 15算法课程 108. Convert Sorted Array to Binary Search Tree
- 15算法课程 242. Valid Anagram
- 15算法课程 110. Balanced Binary Tree
- 15算法课程 226. Invert Binary Tree