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. 用monit监控mongodb,崩溃后自动重启mongdb

    什么是monit Monit是一个跨平台的用来监控Unix/linux系统(比如Linux.BSD.OSX.Solaris)的工具.Monit特别易于安装,而且非常轻量级(只有500KB大小),并且不 ...

  2. 智读App-免费下载付费知识节目攻略

    智读+  知识管理App App下载地址:http://zhidujia.com/ 自助推送工具下载:http://zhidujia.com/product/pushHelper 智读App能帮你做什 ...

  3. Excel技巧--使用规划求解

    当我们需要求在有限预算下可以购买的商品数量时,我们就可以使用“规划求解”功能.如上图,在1000元的预算目标内,我们能购买左图中的各书籍多少本.而这些数量,就可以使用“规划求解”来获取答案. 1.实际 ...

  4. iphone越狱安装python2.7

    cydia  添加源地址:http://apt.so/whitefur 选择python 进行安装 打开ssh连接后输入python 显示python2.7.3 安装成功

  5. 《JavaScript设计模式与开发》笔记 7.单例模式

    废话一箩筐就这个原来 var instance; return function asdf(name){ if(!this.instance){ this.instance = new asdf(na ...

  6. 基于C#的PISDK研究(代码)

    本篇文章主要利用PISDK从PI服务器取数,介绍多种取数方法. 首先需要一些基础的代码,比如获取PI服务的: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  7. 【java】之Method和Field反射获取和设置属性值

    package com.javaluna.reflect; import java.lang.reflect.Field; import java.lang.reflect.Method; impor ...

  8. 使用R语言-操作data.frame

    1 向一个data.frame指定列插入一列新数据 1.1 插入一列到指定位置 y<-1:4 data1 <-data.frame(x1=c(1,3,5,7), x2=c(2,4,6,8) ...

  9. Android开发之动态添加控件

    动态添加TextView控件: 一:创建一个Android project项目 activity_main.xml文件: 1.用两个LinearLayout布局分别包裹一对TextView,EditT ...

  10. 把1,2,3…n*n 的数字按照顺时针螺旋的形式填入数字矩阵

    从键盘输入一个整数(1~20)则以该数字为矩阵的大小,把1,2,3…n*n 的数字按照顺时针螺旋的形式填入其中.例如:输入数字2,则程序输出:1 24 3输入数字3,则程序输出:1 2 38 9 47 ...