Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
解:输入一堆字符串,每一个空格之前的字符串都要反转,拆成一个数组反转之后拼成一个字符串
let array = s.split(' ');
let newArr = [];
for(let i = 0; i < array.length; i++){
let str = array[i].split("").reverse().join("")
newArr.push(str)
}
let newStr = ''
for(let j = 0; j<newArr.length; j++){
if(j == newArr.length-1){
newStr = newStr + newArr[j]
}else{
newStr = newStr + newArr[j] + " "
} }
return newStr

  

leetCode 557. Reverse Words in a String I的更多相关文章

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

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

  2. leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String

    557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public: string reverseWords(string ...

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

  4. [LeetCode] 557. Reverse Words in a String III_Easy tag: String

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  5. Leetcode - 557. Reverse Words in a String III (C++) stringstream

    1. 题目:https://leetcode.com/problems/reverse-words-in-a-string-iii/discuss/ 反转字符串中的所有单词. 2. 思路: 这题主要是 ...

  6. 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 ...

  7. LeetCode 557 Reverse Words in a String III 解题报告

    题目要求 Given a string, you need to reverse the order of characters in each word within a sentence whil ...

  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. 报错: unable to register MBean

    解决方法: 在SpringBoot项目中配置文件加上 spring.jmx.enabled=false https://stackoverflow.com/questions/27440985/una ...

  2. linux du 查看文件及文件夹大小

    1.查看当前目录大小: 如在:/home/jzw/share/ du -sh 1.6G    . 2.查看当前目录下各个文件夹的大小: 如在:/home/jzw/share/ du -sh * 3.6 ...

  3. git初始化项目 以及 git常用操作

    初始化项目 $ git config --global user.name "Your Name"  配置用户名 $ git config --global user.email ...

  4. QT使用SQLite

    在QT的widget中用tableview显示sqlite数据库表中的内容. 用QTcreator创建一个基于Widget类的窗口,再拖一个tableview到widget中,保存. 1.在widge ...

  5. 在Python中进行自动化单元测试的教程

    From: https://www.jb51.net/article/64119.htm 一.软件测试 大型软件系统的开发是一个很复杂的过程,其中因为人的因素而所产生的错误非常多,因此软件在开发过程必 ...

  6. Hadoop概念学习系列之Hadoop新手学习指导之入门需知(二十)

    不多说,直接上干货! 零基础学习hadoop,没有想象的那么困难,也没有想象的那么容易.从一开始什么都不懂,到能够搭建集群,开发.整个过程,只要有Linux基础,虚拟机化和java基础,其实hadoo ...

  7. P1164小A点菜

    传送 这是一个典型的背包方案问题,设f[j]为当前价值为j的方案数,则f[j]=f[j]+f[j-a[i]],即当前方案数为选这个的方案数和不选这个东西的方案数,代码如下 #include<io ...

  8. cmd命令记录

    一.查看端口号的使用情况 参考经验:https://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html 1.netstat -ano,列出所 ...

  9. 峰Redis学习(3)Redis 数据结构(字符串、哈希)

    第一节:Redis 数据类型介绍 五种数据类型: 字符串(String) 字符串列表(list) 有序字符串集合(sorted set) 哈希(hash) 字符串集合(set)   第二节:Redis ...

  10. PAT 乙级 1005 继续(3n+1)猜想 (25) C++版

    1005. 继续(3n+1)猜想 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz ...