leetCode 557. Reverse Words in a String I
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的更多相关文章
- Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)
题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...
- 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 ...
- [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 ...
- [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 ...
- Leetcode - 557. Reverse Words in a String III (C++) stringstream
1. 题目:https://leetcode.com/problems/reverse-words-in-a-string-iii/discuss/ 反转字符串中的所有单词. 2. 思路: 这题主要是 ...
- 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 ...
- 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 ...
- [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& ...
- [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 ...
随机推荐
- 深入理解ASP.NET MVC(3)
系列目录 URL是如何通过路由表生成的(outbound) 通常我们被推荐在view设计时使用Html.ActionLink(…)产生链接,这样做的优势就是,url可以根据路由表生成.路由机制的另一个 ...
- Firedac 数据连接池的应用
procedure TForm2.Button1Click(Sender: TObject); begin if not FDConnection1.Connected then FDConnecti ...
- RedHat6.5安装单机flume1.6
版本号: RedHat6.5 JDK1.8 apache-flume-1.6.0 1.apache-flume-1.6.0-bin.tar.gz 下载 官网下载地址:http://archiv ...
- MyBatis Generator 生成的example 如何使用 and or 简单混合查询
简单介绍: Criteria,包含一个Cretiron的集合,每一个Criteria对象内包含的Cretiron之间是由AND连接的,是逻辑与的关系. oredCriteria,Example内有一个 ...
- 安装老版本redis .NET 客户端
https://github.com/ServiceStackV3/ServiceStackV3 PM> Install-Package ServiceStack -Version 3.9.71 ...
- wsl(Windows Subsystem for Linux)安装简易指南
1. 在“启用或关闭Windows功能”窗口中打开“适用于Linux的Windows子系统”: 2. 让你的Windows更新程序将你的Windows更新到最新版本: 3. 在Microsoft St ...
- C++进阶--处理拷贝赋值运算符中自赋值的情况
//############################################################################ /* * 处理拷贝赋值运算符=中自赋值的情 ...
- Mongodb安装超长等待
最近安装了一下mongodb最新版3.6下载各个版本安装都是停在installing MongoDB Compass位置,网上看到说可以等段时间之类的发现等了1个晚上居然还没成功,取消安装也不行. 于 ...
- tomcat操作
一.启动 D:\tomcat8.5.9\bin\startup 或者 D:\tomcat8.5.9\bin\catalina start 关闭tomcat: D:\tomcat8.5.9\bin ...
- slot内容分发
vue实现了一套内容分发的API,这套API基于当前的web components规范草案,将<slot>元素作为承载分发内容的出口. 在前面的父子组件中,我们提到过,在vue中,组件实例 ...