#-*- coding: UTF-8 -*-
#ZigZag Conversion :之字型
class Solution(object):
    def convert(self, s, numRows):
        """
        :type s: str
        :type numRows: int
        :rtype: str
        """
        if numRows==1:return s
        row=0
        step=1
        zigzag=['' for i in range(numRows)]
        for c in s:
            if row==0:step=1
            if row==numRows-1:
                step=-1
            zigzag[row]+=c
            row+=step
        return "".join(zigzag)
sol=Solution()
print sol.convert("ABC", 2)

【leetcode❤python】 6. ZigZag Conversion的更多相关文章

  1. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  2. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  3. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  4. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  5. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  6. 【leetcode❤python】 168. Excel Sheet Column Title

    class Solution(object):    def convertToTitle(self, n):        """        :type n: in ...

  7. 【leetcode❤python】 7. Reverse Integer

    #-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111.#正因为此, ...

  8. 【leetcode❤python】 189. Rotate Array

    #-*- coding: UTF-8 -*-#由于题目要求不返回任何值,修改原始列表,#因此不能直接将新生成的结果赋值给nums,这样只是将变量指向新的列表,原列表并没有修改.#需要将新生成的结果赋予 ...

  9. 【leetcode❤python】 278. First Bad Version

    #-*- coding: UTF-8 -*-# The isBadVersion API is already defined for you.# @param version, an integer ...

随机推荐

  1. Python开发【杂货铺】:模块logging

    logging模块 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式 ...

  2. 由LazyMan联想到的

    LazyMan问题与解法 http://mp.weixin.qq.com/s/drNGvLZddQztcUzSh8OsSw 给出了一道题目,并给出了解法: 题目: 实现一个LazyMan,可以按照以下 ...

  3. TensorFlow安装(Ubuntu 16.04)

    原文链接 github not support on this platform pip安装: # Ubuntu/Linux 64-bit $ sudo apt-get install python- ...

  4. NOI 05:最高的分数描述

    描述 孙老师讲授的<计算概论>这门课期中考试刚刚结束,他想知道考试中取得的最高分数.因为人数比较多,他觉得这件事情交给计算机来做比较方便.你能帮孙老师解决这个问题吗? 输入输入两行,第一行 ...

  5. XPath 节点

    在 XPath 中,有七种类型的节点:元素.属性.文本.命名空间.处理指令.注释以及文档节点(或称为根节点). XPath 术语 节点(Node) 在 XPath 中,有七种类型的节点:元素.属性.文 ...

  6. Eclipse安装svn插件的几种方式

    Eclipse安装svn插件的几种方式 1.在线安装: (1).点击 Help --> Install New Software... (2).在弹出的窗口中点击add按钮,输入Name(任意) ...

  7. Find cmd

    Find cmd with python programing python at page320 Unix find cmd: find . -name "*.py " -pri ...

  8. Hdu 1214 圆桌会议

    圆桌会议 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. 阿里云推荐码 hut29f

    阿里云 推荐码 hut29f,适用于新手首次购买.

  10. mysql 每秒钟查询次数、插入次数、删除次数、更新次数的统计

    -show global status where Variable_name in('com_select','com_insert','com_delete','com_update'); 查询出 ...