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: 不考虑字符串开头有空格,单词间有多个空格空格的 ...
随机推荐
- legend3---5、lavarel爬坑杂记
legend3---5.lavarel爬坑杂记 一.总结 一句话总结: 边做边学,变学边做,可能会节约很多时间,熟悉的就跳着看,不熟悉的就慢慢看 1.如何tags表中的主键是t_id而非id,如何使用 ...
- C# how to properly make a http web GET request
C# how to properly make a http web GET request EDIT 23/11/17 Updated to throw out examples using asy ...
- Mathematica——绘制3D图形
Plot3D Plot3D[ + y, {x, -, }, {y, -, }] ListPointPlot3D 绘制点集 ListPointPlot3D[{{, , }, {, , }}, Color ...
- SpringMVC——Servlet容器启动时初始化SpringMVC应用的原理
在 Servlet 3.0标准中含有一个 ServletContainerInitializer接口,所有实现了这个接口的类会在容器启动的时候得到一个通知,并且会调用其 onStartup()方法,这 ...
- Android热修复技术原理详解
阿里Dexposed -- native解决方案 原理: 直接在native层进行方法的结构体信息对换,从而实现完美的方法新旧替换,从而实现热修复功能 他的思想完全来源于Xposed框架,完美诠释 ...
- openerp学习笔记 tree视图增加复选处理按钮
wizard:用于确认或选择 wizard/sale_multi_action.py # -*- encoding: utf-8 -*-from openerp.osv import fields, ...
- Android Stuido中断点调试和高级调试
写一个简单的调试程序 import android.os.Bundle; import android.support.v7.app.AppCompatActivity; public class M ...
- 把java项目打包成jar包并可以直接运行【我】
首先创建一个maven的jar项目,然后代码写好后,在项目右键,导出: 选择java下面的可运行的jar文件: 下一步: 要注意的是: launch configuration 此选项是指定选中要导出 ...
- JavaScript DOM 编程艺术(第二版) 有待解决的问题
原书 P181,var repeat = "moveElement('"+elementID+"', "+final_x+", "+fina ...
- 实验一 part2
#include <stdio.h> int main () { int x; printf("输入一个整数:\n"); scanf("%d",&a ...