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. java-http通信调用与创建

    java项目使用HTTP的请求.主要有两种方式:①使用JDK自带的java.net包下的HttpURLConnection方式. ②使用apache的HttpClient方式. 一.使用JDK自带的j ...

  2. Hive介绍和Hive环境搭建

    一.Hive介绍 Hive包含用户接口.元数据库.解析器和数据仓库等组件组成,其中用户接口包含shell客户端.JDBC.ODBC.Web接口等.元数据库主要是指定义在hive中的表结构信息,一般保存 ...

  3. SpringBoot+Maven 多模块项目的构建、运行、打包

    SpringBoot+Maven 多模块项目的构建.运行.打包 https://blog.csdn.net/zekeTao/article/details/79413919

  4. nginx基于目录的映射:

    nginx基于目录的映射: location /wxchat/ { #proxy_redirect off; proxy_set_header Host $host; proxy_set_header ...

  5. PHP优化思路

    想起来记录一下自己对PHP的优化思路 针对Nginx和 PHP-FPM进行优化 首先应该分为代码层面.配置层面.架构层面 代码层面 参见了https://segmentfault.com/a/1190 ...

  6. Nuke的色彩匹配节点思路

    大致思路是首先利用node.sample()自带采样功能对整个画面逐像素采 样,我把采样函数写的比较灵活,可以定义一个采样族,即把整个画面分成若干块,逐块采样,很大程度上减少了采样工作量,但相对精度会 ...

  7. C#实现设置系统时间

    using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Demo { pub ...

  8. wxPython 入门开发示例

    1.背景资料 wxPython API:https://www.wxpython.org/Phoenix/docs/html/ 2.入门示例 wxPython最重要的两个概念:App与Frame,其中 ...

  9. windows下python2和python3同时安装ipython

    1.ipython简介: IPython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许 ...

  10. console.log()换行和document.write()换行

    <!DOCTYPE html><html ><head><meta charset="utf-8"><title>ddd ...