Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".

 public class Solution {
public String reverseWords(String s) {
if(s.equals(""))return s;
String arr[]=s.split(" ");
String new_word="";
for(int i=arr.length-1;i>=0;i--)
{
if(arr[i].equals(""))continue;
new_word+=arr[i]+" ";
}
new_word=new_word.toString().trim();
return new_word;
}
}

做完以后看了别人的答案 发现有用StringBuilder

所以又去学习了一下这个三个的区别 在100000复杂度下 StringBulder和buffer比string快的就不是一点了

所以:

1.如果要操作少量的数据用 = String

2.单线程操作字符串缓冲区 下操作大量数据 = StringBuilder 
3.多线程操作字符串缓冲区 下操作大量数据 = StringBuffer

Reverse Words in a String (JAVA)的更多相关文章

  1. leetcode 151. Reverse Words in a String --------- java

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

  2. 151. Reverse Words in a String(java 注意细节处理)

    题目:reverse words in a string Given an input string, reverse the string word by word. For example,Giv ...

  3. [LeetCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  4. LeetCode Reverse Words in a String II

    原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string, rever ...

  5. leetcode面试准备:Reverse Words in a String

    leetcode面试准备:Reverse Words in a String 1 题目 Given an input string, reverse the string word by word. ...

  6. LeetCode: Reverse Words in a String 解题报告

    Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...

  7. LeetCode解题报告—— Linked List Cycle II & Reverse Words in a String & Fraction to Recurring Decimal

    1. Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no ...

  8. [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& ...

  9. [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 ...

随机推荐

  1. 总结oninput、onchange与onpropertychange事件的用法和区别 书写搜索的神奇代码

    总结oninput.onchange与onpropertychange事件的用法和区别 最近手机开发一个模糊搜索的功能组建,在网上就找到这篇文章! 前端页面开发的很多情况下都需要实时监听文本框输入,比 ...

  2. UINavigationController 导航控制器

    一.导航视图控制器 1.管理视图控制器 2.控制视图控制器之间的跳转 3.是以压栈和出栈的形式来管理视图控制器 4.导航视图控制器必须要设置根视图控制器 5.导航是视图控制器包含UINavigatio ...

  3. javascript版1024游戏源码

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. ExtJS 创建动态加载树

    Ext 中导航树的创建有两种方式:1.首先将所有的数据读出来,然后绑定到前台页面.2.每点击一个节点展开后加载子节点.在数据量比较小的时候使用第一种方式加载的会快一些,然而当数据量比较大的时候,我还是 ...

  5. Yii CDbCriteria的常用方法

    $criteria = new CDbCriteria; $criteria->addCondition("id=1"); //查询条件,即where id = 1 $cri ...

  6. Excel Aspose.Cells 设置单元格格式 为数字

    Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[]; //工作表 sheet.Cells ...

  7. 微信订阅号开发之token验证后,自动回复消息功能做好,发送消息没有返回

    相信很多人会跟我一样,token验证之后,发送消息给订阅号,没有消息返回. 以下,说一下我辛苦调试得到的解决办法: 首先,token验证: 自己写的token一直验证失败,找了好久,没有发现bug.实 ...

  8. ASP.NET MVC 4.0 学习2-留言板實現

    新增專案實現留言板功能,瞭解MVC的運行機制 1,新增專案   2,添加數據庫文件message.mdf   Ctrl+W,L 打開資料庫連接,添加存放留言的Atricle表 添加字段,後點擊&quo ...

  9. Linux dirname、basename(转)

    首先使用 --help 参数查看一下.basename命令参数很少,很容易掌握. $ basename --help 用法示例: $ basename /usr/bin/sort       输出&q ...

  10. Windows XP SP3中远程桌面实现多用户登陆

    Windows XP SP3配置为支持多用户远程桌面连接,注意:此多用户远程桌面连接必须是不同的用户登录,不能像Windows server 2003那样,同一个用户可以同时登录,只能登陆2个不同用户 ...