leetcode 151. Reverse Words in a String
来源:互联网 发布:淘宝店铺如何优化 编辑:程序博客网 时间:2024/06/18 13:59
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.
click to show clarification.
Subscribe to see which companies asked this question.
public class Solution { public String reverseWords(String s) { if(s.length()==0) return s; String[] words=s.split(" "); String str=""; LinkedList<String> list=new LinkedList<>(); for(int i=0;i<words.length;i++){ if(words[i].length()>0)list.addFirst(words[i]); } for(int i=0;i<list.size()-1;i++){ str=str+list.get(i)+" "; } if(list.size()>0){ str=str+list.get(list.size()-1); } return str; }}
0 0
- LeetCode 151. Reverse Words in a String
- LeetCode 151. Reverse Words in a String
- [LeetCode]151.Reverse Words in a String
- [leetcode] 151.Reverse Words in a String
- Leetcode-151.Reverse Words in a String
- Leetcode 151. Reverse Words in a String
- [leetcode]151. Reverse Words in a String
- LeetCode 151. Reverse Words in a String
- Leetcode 151. Reverse Words in a String
- LeetCode *** 151. Reverse Words in a String
- LeetCode-151.Reverse Words in a String
- leetcode 151. Reverse Words in a String
- LeetCode - 151. Reverse Words in a String
- [leetcode] 151. Reverse Words in a String
- [Leetcode]151. Reverse Words in a String
- leetcode 151. Reverse Words in a String
- [LeetCode] 151. Reverse Words in a String
- Leetcode-151. Reverse Words in a String
- 51 NOD 1135 原根
- Linux系统之网络编程[基础概要]
- 196. Delete Duplicate Emails
- Numpy学习笔记之利用数组处理数据
- 模拟ATM取款机
- leetcode 151. Reverse Words in a String
- 求无向图中的三元环个数
- [LeetCode] Assign Cookies 分饼干
- android采集应用打开次数和cpu信息
- LeetCode-547. Friend Circles(JAVA)朋友圈数量
- 剑指offer 和为S的连续正数序列
- c语言实现简单的三子棋
- 用php判断当前时间是否在每天的某一时间区域内,比如: 9:00-18:00
- 浅析进程和task_struct