本篇文章主要介绍了" 字符串-Reverse Words in a String(翻转字符串)",主要涉及到方面的内容,对于Javajrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
问题描述:Given an input string, reverse the string word by word.For example,Given s ...
问题描述:
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
Update (2015-02-12):
For C programmers: Try to solve it in-place in O(1) space.
思考:
关键在于对空格的剔除和对字符串的索引的把握,思路就是使用一个result字符串类累加保存结果,把顺序寻找的字符串添加在result的0位置上,那么后面的索引向后向后全部移动新字符串长度。
代码(java):
public class Solution {
public String reverseWords(String s) {
int begin = 0;
int end = 0;
if(s==null) {
return s;
}
while(begin<>
以上就介绍了 字符串-Reverse Words in a String(翻转字符串),包括了方面的内容,希望对Javajrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_1804013.html