Leetcode 151(Java)
来源:互联网 发布:第一会软件 编辑:程序博客网 时间:2024/06/05 18:26
Total Accepted: 154413
Total Submissions: 982629
Difficulty: Medium
Contributor: LeetCode
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.
自己写出来以后看了别人的代码,精简的多。主要是自己对于JAVA自带的方法还不是特别的熟悉,AC码如下,要注意在split()方法中,‘+’号是正则表达式里的意思,如果真正要使用+号需要转义:
public String reverseWords(String s) { String[] substr = s.trim().split(" +"); Collections.reverse(Arrays.asList(substr)); return String.join(" ",substr); }
阅读全文
0 0
- Leetcode 151(Java)
- leetcode整理(java)
- Leetcode 543(Java)
- Leetcode 389(Java)
- Leetcode 387(Java)
- Leetcode 207(Java)
- leetcode 49(java)
- Leetcode 463(Java)
- Leetcode 506(Java)
- Leetcode 22(Java)
- Leetcode 628(Java)
- Leetcode 645(Java)
- LeetCode-Java (一)
- Leetcode-Java (二)
- Leetcode-Java (三)
- Leetcode-Java (四)
- Leetcode(java)
- leetcode java
- 什么时候使用字节流、什么时候使用字符流,二者的区别
- Unix、Posix和标准UniX规范
- 自定义View练习
- P1209 几何图形还原
- Android笔记五(Binder例子)
- Leetcode 151(Java)
- .Net实现邮件定时发送问题总结
- 【ubuntu】1404 安装ssh-server时出现错误
- hdu1496—Equations(枚举)
- 数据结构实验之栈七:出栈序列判定
- Win2008系统创建DNS服务器
- 蓝桥-ALGO-24-统计单词个数
- Java Swing2 基本登录框
- LeetCode 44. Wildcard Matching