LintCode 53---翻转字符串中的单词
public class Solution {
/*
* @param s: A string
* @return: A string
*/
public static String reverseWords(String s) {
if(s==null || s.length() == 0) return "";
String[] array = s.split(" ");
StringBuilder sb = new StringBuilder();
for (int i = array.length - 1; i>=0; --i) {
if(!array[i].equals("")){
sb.append(array[i]).append(" ");
}
}
return sb.toString();
}
}
LintCode 53---翻转字符串中的单词的更多相关文章
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- [LeetCode] 151. Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- [LeetCode] 186. Reverse Words in a String II 翻转字符串中的单词 II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- [LeetCode] 557. Reverse Words in a String III 翻转字符串中的单词 III
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
- [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- [LeetCode] Reverse Words in a String III 翻转字符串中的单词之三
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
- LeetCode刷题:Reverse Words in a String(翻转字符串中的单词)
题目 Given an input string, reverse the string word by word. For example, Given s = "the sky is b ...
- [LintCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- [Swift]LeetCode186. 翻转字符串中的单词 II $ Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- java翻转字符串中的单词
效果: 输入: "java and python" 输出: "avaj dna nohtyp" 代码: 版本1: 不考虑字符串开头有空格,单词间有多个空格空格的 ...
随机推荐
- LeetCode 179. 最大数(Largest Number)
题目描述 给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 示例 1: 输入: [10,2] 输出: 210 示例 2: 输入: [3,30,34,5,9] 输出: 9534330 说明: ...
- android data binding jetpack V 实现recyclerview 绑定
android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...
- __declspec(dllexport)的使用
1. 用法 在 VS 的“预编译”选项里定义_EXPORTING宏 #ifdef _EXPORTING #define API_DECLSPEC __declspec(dllexport) #else ...
- nginx环境准备
一.环境调试确认 1.四项确认 确认公网已连通. 确认yum源可用. 确认iptables已经关闭. 确认selinux已经关闭. a.确认是否连通公网. ping www.baidu.com b.确 ...
- P2983 [USACO10FEB]购买巧克力
P2983 [USACO10FEB]购买巧克力 题解 注意题目开 long long 贪心策略:价格从低到高,买够为止 反证:若剩下的有一个K”,比K小,那么交换,稳赚不赔 所以,在买K之前,所有比他 ...
- Linux命令之文件和目录操作命令(一)—— ls
本文介绍了ls命令的最常用法. 1.用法: ls [选项][目录名或文件名] 2.选项: -l 使用长格式显示目录或文件的详细信息 -a 显示隐藏文件 -h 人性化显示文件或目录的大小 -d 显示目录 ...
- javascript的历史和入门
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 微信小程序开发工具下载以及安装教程
微信公众平台上登录你的微信小程序账号 登录进入小程序开发-工具-下载,再根据你的系统选择相对应的版本地址进行下载. 以管理员身份运行下载,点击下一步,如图所示: 下一步,就会出现许可证协议 ...
- ZeroC ICE java异步实现方式(ami/amd)
首先说说ami 和amd 的区别(以下为个人见解,仅供参考.如有疑问欢迎提出来) ami (异步方法调用): 仅仅基于ice 的同步方式扩展了异步的扩展方式,其他理念改动不大,使用起来好理解,但是服务 ...
- 配置文件 "G:\虚拟机列表\Linux001.vmx" 由产品 VMware 创建, 其版本 VMware Workstation 不兼容并且不能使用.
解析: 报这种错误一般是虚拟机文件里声明的VMware版本和真实的VMware版本不一致导致.我们可以手动更改真实VMware版本,或者更改虚拟机文件里声明的VMware版本.以下我们通过更该虚拟机文 ...