557. 反转字符串中的单词 III

给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。

示例 1:

输入: “Let’s take LeetCode contest”

输出: “s’teL ekat edoCteeL tsetnoc”

注意:在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格。

class Solution {
public String reverseWords(String s) {
String[] strs = s.split(" ");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < strs.length; i++) {
buffer.append(new StringBuffer(strs[i]).reverse().toString());
buffer.append(" ");
}
return buffer.toString().trim();
}
}

Java实现 LeetCode 557 反转字符串中的单词 III(StringBuilder的翻转和分割)的更多相关文章

  1. C#版(击败97.76%的提交) - Leetcode 557. 反转字符串中的单词 III - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. Leetcod ...

  2. Leetcode 557.反转字符串中的单词III

    反转字符串中的单词III 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest ...

  3. Leetcode 557. 反转字符串中的单词 III

    1.题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" ...

  4. 557. 反转字符串中的单词 III

    给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输出: &q ...

  5. leetcode-解题记录 557. 反转字符串中的单词 III

    题目: 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输出 ...

  6. 557反转字符串中的单词III

    class Solution: # 定义一个反转字符串的函数. def str_rever(self,s): length = len(s) s1 = '' for index in range(le ...

  7. leetcode python反转字符串中的单词

    # Leetcode 557 反转字符串中的单词III### 题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. **示例1:** 输入: "L ...

  8. Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)

    题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...

  9. LeetCode557 反转字符串中的单词 III

    给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输出: &q ...

随机推荐

  1. Druid 0.17入门(4)—— 数据查询方式大全

    本文介绍Druid查询数据的方式,首先我们保证数据已经成功载入. Druid查询基于HTTP,Druid提供了查询视图,并对结果进行了格式化. Druid提供了三种查询方式,SQL,原生JSON,CU ...

  2. Luogu P3389 高斯消元

    https://www.luogu.com.cn/problem/P3389 主元消元法[模板] 高斯消元是解决多元线性方程组的方法,再学习它之前,先引入一个东西--行列式 行列式的性质: 这里我们只 ...

  3. Springboot Mybatis 打包jar扫描bean与mapper问题研究与解决

    SpringBootLean 是对springboot学习与研究项目,是根据实际项目的形式对进行配置与处理,欢迎star与fork. [oschina 地址] http://git.oschina.n ...

  4. html5 canvas画云

    使用函数画出天空的云层图像: y 主要使用到的是数学的圆与弧度之间转换关系: 代码如下 //div对象 var parentContainer = document.getElementById(&q ...

  5. JSP+Servlet+JDBC+mysql实现的个人日记本系统

    项目简介 项目来源于:https://gitee.com/wishwzp/Diary 本系统基于JSP+Servlet+Mysql 一个基于JSP+Servlet+Jdbc的个人日记本系统.涉及技术少 ...

  6. Codeforces 1105D(Kilani and the Game,双队列bfs)

    AC代码: #include<bits/stdc++.h> #define ll long long #define endl '\n' #define mem(a,b) memset(a ...

  7. react-grid-layout实现拖拽,网格布局

    借鉴地址:https://www.jianshu.com/p/b48858eee3a7 安装 react-grid-layout npm install react-grid-layout impor ...

  8. ubuntu下图形程序自启动的几种方法

    版权声明:本文为本文为博主原创文章,转载请注明出处.如有问题,欢迎指正.博客地址:https://www.cnblogs.com/wsg1100/ @ 目录 0.前言 1.带桌面环境的自动启动 1.1 ...

  9. 适配器模式C++实现

    目录 类适配器 对象适配器 类适配器 #include <iostream> using namespace std; // Target class Target { public: v ...

  10. xpython操作excel之xlwt与xlrd

    xlwt与xlrd只能针对xls格式的excel进行操作!!!(openpyxl操作excel) xlwt写excel # pip install xlwt下载导入xlwt写xls格式的excel操作 ...