class Solution {
public:
string convert(string s, int nRows) {
if (nRows <= 1) return s;
string res = "";
int size = 2 * nRows - 2;
for (int i = 0; i < nRows; ++i) {
for (int j = i; j < s.size(); j += size) {
res += s[j];
int tmp = j + size - 2 * i;
if (i != 0 && i != nRows - 1 && tmp < s.size()) res += s[tmp];
}
}
return res;
}
};

leetcode 6 ZigZag Converesion的更多相关文章

  1. [LeetCode] 6. ZigZag Converesion 之字型转换字符串

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  2. [LeetCode] ZigZag Converesion 之字型转换字符串

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  3. LeetCode 6 ZigZag Conversion 模拟 难度:0

    https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...

  4. leetcode 6. ZigZag Conversion

    https://leetcode.com/problems/zigzag-conversion/ 题目: 将字符串转化成zigzag模式. 例如 "abcdefghijkmlnpq" ...

  5. LeetCode 6 ZigZag Conversion(规律)

    题目来源:https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is writt ...

  6. [LeetCode][Python]ZigZag Conversion

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/zigzag- ...

  7. LeetCode——6. ZigZag Conversion

    一.题目链接:https://leetcode.com/problems/zigzag-conversion/description/ 二.题目大意: 给定一个字符串和一个数字,将其转换成Zigzag ...

  8. 蜗牛慢慢爬 LeetCode 6. ZigZag Conversion [Difficulty: Medium]

    题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...

  9. [LeetCode 题解]: ZigZag Conversion

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 The string ...

随机推荐

  1. django的settings文件

    转载:http://www.cnblogs.com/likeshan168/articles/3596344.html

  2. swing之记事本的简单实现

    package gui1; import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JButton ...

  3. vbs查看系统开关机时间

    如何获取XP系统的开机时间? 下面给出两种代码,保存到扩展名为vbs的文件中.具体哪个请根据自己需求决定. 一:根据系统日志,查看开机时间和关机时间,---- 使用弹出对话框的形式 Set WMI = ...

  4. Qt Creator 中自动补全的快捷键描述

    在TextEdit中的completeThis

  5. Spring基础知识之装配Bean

    装配(wiring):创建应用对象之间协作关系的行为.这是依赖注入的本质. Spring配置的可选方案 Spring提供了三种装配机智: 1)在XML中进行显示装配 2)在java中进行显示装配 3) ...

  6. 命令"service 服务名 restart" 与 "service 服务名 reload"的区别

    由于今天用到了service nginx reload 和 service nginx restart,说说他俩的区别吧: reload:不间断服务重启,就像一张网页上面的刷新按钮一样. restar ...

  7. TFSEclipsePlugin-UpdateSiteArchive 手动拷贝

  8. Day3-Python基础3--局部变量和全局变量

    一.局部变量 def test(name): print("before change:",name) name = "maqing" #局部变量name,只能 ...

  9. Python中try...except...else的用法

    Python中try...except...else的用法: try:    <语句>except <name>:    <语句>          #如果在try ...

  10. Rails上传文件

    1.view <%= form_tag({:method =>"post",:controller =>"welcome",:action=& ...