problem describe:

  given a string , first find the first word which is not white space;then there will be an optional '+' or '-', but the given the test set the given string will contain more than one symbol or didn't contain any number, if that you should return 0;third,you should find as many  number as possible,and change the string num into int.if the num more than 2^31-1 or smaller than -2^31, you should return 2^31- 1 or  -2^31.

i.e.

input '+-2'

output '0'

my python solution:

class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
slength = len(s)
full, leave = divmod(slength, (numRows+numRows/2))
left, right = divmod(leave, numRows)
returnlist = []
times = full
k = 0
if left == 0:
left = right
right =0
for i in range(numRows):
if i%2 != 0:
for colnum in range(times):
returnlist[k] = s[i+(3*numRows/2)*times]
k += 1
if left != 0:
if i+(3*numRows/2)*(times+1)<= slength:
returnlist[k] = s[i+(3*numRows/2)*(times+1)]
k += 1
else:
for colnum in range(times):
returnlist[k] = s[i+(3*numRows/2)*times]
k = k+1
returnlist[k] = s[numRows+i/2+ (3*numRows/2)*times]
k += 1
if left !=0 and i+(3*numRows/2)*(times+1)<slength:
returnlist[k] = s[i+(3*numRows/2)*(times+1)]
k += 1
if right != 0 and numRows+i/2+ (3*numRows/2)*(times+1)<slength:
returnlist[k] = s[numRows+i/2+ (3*numRows/2)*(times+1)]
k += 1
need = ''
for each in returnlist:
need += each
return need

string to int的更多相关文章

  1. C#中String转int问题

    String转int主要有四种方法 1. int.Parse()是一种类容转换:表示将数字内容的字符串转为int类型. 如果字符串为空,则抛出ArgumentNullException异常: 如果字符 ...

  2. 编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试Stud

    package zuoye; public class student { int age; String name; int stuNO; void outPut() { System.out.pr ...

  3. js string to int

    一.js中string转int有两种方式 Number() 和 parseInt() <script>     var   str='1250' ;  alert( Number(str) ...

  4. LeetCode 8 String to Integer (string转int)

    题目来源:https://leetcode.com/problems/string-to-integer-atoi/ Implement atoi to convert a string to an ...

  5. java 13-4 Integer和String、int之间的转换,进制转换

    1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...

  6. swift 中String,Int 等类型使用注意,整理中

    swfit中的String和Int是 struct定义的,不同于NSString和NSNumber, 如果想在一个数组中同时包含String和Int,那么这个数组要声明为[Any] 而不是 [AnyO ...

  7. 首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试Student类的功能。

    package lianxi; public class Student { String Name; int XveHao,Age; Student(String Name,int XveHao,i ...

  8. caffe: compile error : undefined reference to `cv::imread(cv::String const&, int)' et al.

    when I compile caffe file : .build_debug/lib/libcaffe.so: undefined reference to `cv::imread(cv::Str ...

  9. java中字符串String 转 int(转)

    java中字符串String 转 int String -> int s="12345"; int i; 第一种方法:i=Integer.parseInt(s); 第二种方法 ...

  10. std::string和int类型的相互转换(C/C++)

    字符串和数值之前转换,是一个经常碰到的类型转换. 之前字符数组用的多,std::string的这次用到了,还是有点区别,这里提供C++和C的两种方式供参考: 优缺点:C++的stringstream智 ...

随机推荐

  1. 从JDK源码角度看线程池原理

    "池"技术对我们来说是非常熟悉的一个概念,它的引入是为了在某些场景下提高系统某些关键节点性能,最典型的例子就是数据库连接池,JDBC是一种服务供应接口(SPI),具体的数据库连接实 ...

  2. Java 8新特性探究(二)类型注解和重复注解

    本文将介绍java 8的第二个特性:类型注解. 注解大家都知道,从java5开始加入这一特性,发展到现在已然是遍地开花,在很多框架中得到了广泛的使用,用来简化程序中的配置.那充满争议的类型注解究竟是什 ...

  3. awk 详解+实例

    1. awk简介 awk是一种编程语言,用于在linux/unix下对文本和数据进行处理.数据可以来自标准输入.一个或多个文件,或其它命令的输出.它支持用户自定义函数和动态正则表达式等先进功能,是li ...

  4. DB 查询分析器 方便地创建DB2自定义函数

    DB 查询分析器 方便地创建DB2自定义函数                           马根峰            (广东联合电子服务股份有限公司, 广州 510300) 摘要       ...

  5. AngularJS进阶(二)AngularJS路由问题解决

    AngularJS路由问题解决 遇到了一个棘手的问题:点击优惠详情时总是跳转到药店详情页面中去.再加一层地址解决了,但是后来发现问题还是来了: Could not resolve 'yhDtlMain ...

  6. Java-Cookie源码

    public class Cookie implements Cloneable { private static final String LSTRING_FILE = "javax.se ...

  7. windows linux—unix 跨平台通信集成控制系统

    首先,我们可以用到这个开源的开发包: mdk(Micro-Development-Kit)微量级软件开发包,提供几个常用类,主要实现了一个高性能的并发服务器引擎 使用c++开发,是一个跨平台的开发包, ...

  8. Bookmarkable Pages

      Build a Bookmarkable Edit Page with JDeveloper 11g Purpose In this tutorial, you use Oracle JDevel ...

  9. C++之默认参数

    C++可以为不指定参数提供默认值.一旦给一个参数赋了默认值,后面的所有参数,也都必须为默认值,并且默认值的类型也必须正确,默认值可以在原型或者函数定义中给出,但是不能两个位置同时给出. 接下来我们上代 ...

  10. html5标签基础

    1.声明:<!DOCTYPE> HTML有多个不同的版本,只有完全明白页面中使用的确切HTML版本,浏览器才能完全正确的显示出HTML页面,这就是<!DOCTYPE>的用处. ...