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. ROS(indigo)_turtlebot仿真示例包括stage和gazebo

    ROS(indigo)_turtlebot仿真示例包括stage和gazebo 现上参考网址: turtlebot:http://wiki.ros.org/Robots/TurtleBot stage ...

  2. python字典(dictionary)使用:基本函数code实例,字典的合并、排序、copy,函数中*args 和**kwargs做形参和实参

    python字典dictionary几个不常用函数例子 一.字典声明 如,d={}; d= {'x':1,'b':2} d1 = dict(x=1,y=2,z=3)     d2 = dict(a=3 ...

  3. Leetcode_7_Reverse Integer

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41578077 Reverse Integer Revers ...

  4. 小强的HTML5移动开发之路(7)——坦克大战游戏1

    来自:http://blog.csdn.net/dawanganban/article/details/17693145 上一篇中我们介绍了关于Canvas的基础知识,用Canvas绘制各种图形和图片 ...

  5. Linux 中环境变量设置

    本文主要整理自以下博文: .bash_profile和.bashrc的什么区别及启动过程 linux环境变量设置方法总结(PATH/LD_LIBRARY_PATH) .bash_profile 和 . ...

  6. android自定义listview实现header悬浮框效果

    之前在使用iOS时,看到过一种分组的View,每一组都有一个Header,在上下滑动的时候,会有一个悬浮的Header,这种体验觉得很不错,请看下图: 上图中标红的1,2,3,4四张图中,当向上滑动时 ...

  7. (十六)TableView常见属性

    千万不要忘记设置TableView的数据源. 1.分割线的样式: separatorStyle与separatorColor. 颜色:十六进制表示 32bit:argb各占8位. #aarrggbb ...

  8. STL算法设计理念 - 函数适配器

    1)函数适配器的理论知识 2)常用函数函数适配器 标准库提供一组函数适配器,用来特殊化或者扩展一元和二元函数对象.常用适配器是: 1.绑定器(binder): binder通过把二元函数对象的一个实参 ...

  9. 【翻译】在Ext JS应用程序中使用自定义图标

    原文:Using Custom Icons in Your Ext JS App 作者:Lee BoonstraLee is a technical trainer at Sencha. She's ...

  10. C语言颜色转换宏

    C语言颜色转换宏 #define COLOR_BPP16_RGB555 /* Win RGB */ #define COLOR_RGB(r,g,b) ((COLORREF)(((BYTE)(r)|(( ...