LeetCode557 Reverse Words in a String III
来源:互联网 发布:外汇行情软件哪个好 编辑:程序博客网 时间:2024/06/09 20:07
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:Input: "Let's take LeetCode contest"Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by single space and there will not be any extra space in the string.
//中间多个空格会保留
解法:
public class Solution { public String reverseWords(String s) { String[] strs = s.split(" "); StringBuilder sb = new StringBuilder(); for(String str: strs){ StringBuilder temp = new StringBuilder(str); sb.append(temp.reverse()); sb.append(" "); } return sb.toString().trim(); }}知识点:
StringBuilder/StringBuffer 的reverse方法可以把字符串翻转,注意:String没这个方法
阅读全文
0 0
- leetcode557. Reverse Words in a String III
- leetcode557. Reverse Words in a String III
- LeetCode557 Reverse Words in a String III
- Leetcode557. Reverse Words in a String III
- python--leetcode557. Reverse Words in a String III
- 15.leetCode557: Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- leetocde557: Reverse Words in a String III
- oj557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- vim的安装及配置
- hdu 3037 Saving Beans Lucas定理
- 约瑟夫环
- Leetcode 1.Two Sum
- 森林转化为树
- LeetCode557 Reverse Words in a String III
- 225. Implement Stack using Queues
- c++11特性之initializer_list
- 如何判断一家软件公司是否靠谱
- tensorflow安装出现Failed to load the native TensorFlow runtime问题
- proxifier配合ss,实现全局代理
- Java static关键字,final关键字
- SeetaFace C++环境搭建(详细图文)
- leveldb(七):Memtable