Leetcode 6 ZigZag Conversion 字符串处理
题意:将字符串排成Z字形。
PAHNAPLSIIGYIR 如果是5的话,是这样排的
P I
AP YR
H L G
N SI
A I
于是,少年少女们,自己去找规律吧
提示:每个Z字形的字符串和原字符串的每个字母的位子一一映射
class Solution {
public:
string convert(string s, int numRows) {
string t = s;
if(numRows == ) return t;
int k = ;
for(string::size_type i = ; i < s.size(); i += * numRows - ){
t[k++] = s[i];
}
for(int i = ; i < numRows - ; ++i){
for(string::size_type j = i; j < s.size(); j += * numRows - ){
t[k++] = s[j];
if(j + * numRows - - * i< s.size()) {
t[k++] = s[j + * numRows - - * i];
}
}
}
for(string::size_type i = numRows - ; i < s.size(); i += * numRows - ){
t[k++] = s[i];
}
return t;
}
};
Leetcode 6 ZigZag Conversion 字符串处理的更多相关文章
- LeetCode 6. ZigZag Conversion & 字符串
ZigZag Conversion 看了三遍题目才懂,都有点怀疑自己是不是够聪明... 就是排成这个样子啦,然后从左往右逐行读取返回. 这题看起来很简单,做起来,应该也很简单. 通过位置计算行数: P ...
- [leetcode]6. ZigZag Conversion字符串Z形排列
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- Java [leetcode 6] ZigZag Conversion
问题描述: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...
- Leetcode 6. ZigZag Conversion(找规律,水题)
6. ZigZag Conversion Medium The string "PAYPALISHIRING" is written in a zigzag pattern on ...
- [LeetCode] 6. ZigZag Conversion 之字型转换字符串
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- 蜗牛慢慢爬 LeetCode 6. ZigZag Conversion [Difficulty: Medium]
题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...
- LeetCode 6 ZigZag Conversion 模拟 难度:0
https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...
- leetcode 6. ZigZag Conversion
https://leetcode.com/problems/zigzag-conversion/ 题目: 将字符串转化成zigzag模式. 例如 "abcdefghijkmlnpq" ...
- LeetCode 6 ZigZag Conversion(规律)
题目来源:https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is writt ...
随机推荐
- 6.HotSpot垃圾收集器
HotSpot JVM收集器 上面有7中收集器,分为两块,上面为新生代收集器,下面是老年代收集器.如果两个收集器之间存在连线,就说明它们可以搭配使用. 并发和并行 先解释下什么是垃圾收集器的上下文语境 ...
- FZU 1894 志愿者选拔 (单调队列)
/****************************************************************** 题目: 志愿者选拔(FZU 1894) 算法: 单调队列 算法思 ...
- calc()问题
什么是calc()? 学习calc()之前,我们有必要先知道calc()是什么?只有知道了他是个什么东东?在实际运用中更好的使用他. calc() 从字面我们可以把他理解为一个函数function.其 ...
- Python学习之正则表达式
引用类: import re 常用方法: re.compile(pattern) re.match() re.search() re.findall() group() groups() re.spl ...
- [Chapter 3 Process]Practice 3.3 Discuss three major complications that concurrent processing adds to an operating system.
3.3 Original version of Apple's mobile iOS operating system provied no means of concurrent processi ...
- 两个不等式(Nopier)
- Win7 64位 VS2013环境编译CGAL-4.7
看到有人在QQ空间感叹编译CGAL配置折腾了一天时间,自己也想试试,虽然并不打算用,但感觉这库也挺有名的,想必日后用得着,于是着手试着编译. 首先是看一下官网的windows下配置说明 http:// ...
- sql2008日志文件截断
日志文件比较大时,使用语句减少大小. USE DATABASENAME;GO-- Truncate the log by changing the database recovery model to ...
- React Native填坑之旅--ListView篇
列表显示数据,基本什么应用都是必须.今天就来从浅到深的看看React Native的ListView怎么使用.笔者写作的时候RN版本是0.34. 最简单的 //@flow import React f ...
- poj 3635/hdu 1676 Full Tank? 车辆加油+最短路
http://acm.hdu.edu.cn/showproblem.php?pid=1676 给出一张图,n<=1000,m<=10000. 有一辆车想从图的一个地方到达另外一个地方,每个 ...