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 ...
随机推荐
- JMeter ----与WebDriver安装与测试
JMeter ----与WebDriver安装与测试 主要内容 JMeter安装 WebDriver安装 一个简单的JMeter+WebDriver示例 环境与参考 jvm版本: 1.8.0_65 j ...
- mysql编译安装(详细)(转载)
mysql编译安装(详细) 一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 yum install gcc gcc-c++ ncurses-devel perl 安装cmake,从 ...
- WPF Demo16 资源
<Window x:Class="RescourceDemo1.MainWindow" xmlns="http://schemas.microsoft.com/wi ...
- ios导航栏和tabbar的坑
多年不写ios,目前重构项目,发现navBar和tabbar需要注意的点,记录备忘 translucent属性会导致view起始点的变化,默认为透明,和设计图有色差,改成不透明以后,坐标位置有变化,修 ...
- [蓝桥杯]ALGO-51.算法训练_Torry的困惑(基本型)
题目描述: 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2...……这样的数叫做质数.Torry突然想到一个问题,前10...……个质数的乘积是多少呢?他把这个问题告诉老师.老师愣住了,一时 ...
- ALGO-126_蓝桥杯_算法训练_水仙花
问题描述 判断给定的三位数是否 水仙花 数.所谓 水仙花 数是指其值等于它本身 每位数字立方和的数.例 就是一个 水仙花 数. =++ 输入格式 一个整数. 输出格式 是水仙花数,输出"YE ...
- Mina - 模拟同步请求
这篇博客主要就铺代码吧,Mina的一些基础知识可以参考: http://www.cnblogs.com/huangfox/p/3458272.html 场景假设: 1.客户端发送用户信息,服务端根据用 ...
- VisualSVNServer 无法启动 could not log pid to file
启动SVN时候报了错误,然后查看日志发现报了如下错误 VisualSVNServer.exe: could not log pid to file C:/Windows/ServiceProfiles ...
- Flume 安装和配置
安装步骤 1.安装jdk,1.6版本以上 2.上传flume的安装包 3.解压安装 4.在conf目录下,创建一个配置文件,比如:template.conf(名字可以不固定,后缀也可以不固定) 5.配 ...
- 浙江财经大学第十五届大学生程序设计竞赛------B 烦恼先生打麻将
问题 B: B - 烦恼先生打麻将 时间限制: 1 Sec 内存限制: 256 MB提交: 8 解决: 5[提交][状态][讨论版] 题目描述 输入 6 6 Z D 1S 1S 9W 5W 2S ...