string to int
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的更多相关文章
- C#中String转int问题
String转int主要有四种方法 1. int.Parse()是一种类容转换:表示将数字内容的字符串转为int类型. 如果字符串为空,则抛出ArgumentNullException异常: 如果字符 ...
- 编写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 ...
- js string to int
一.js中string转int有两种方式 Number() 和 parseInt() <script> var str='1250' ; alert( Number(str) ...
- LeetCode 8 String to Integer (string转int)
题目来源:https://leetcode.com/problems/string-to-integer-atoi/ Implement atoi to convert a string to an ...
- java 13-4 Integer和String、int之间的转换,进制转换
1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...
- swift 中String,Int 等类型使用注意,整理中
swfit中的String和Int是 struct定义的,不同于NSString和NSNumber, 如果想在一个数组中同时包含String和Int,那么这个数组要声明为[Any] 而不是 [AnyO ...
- 首先,定义描述学生的类——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 ...
- 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 ...
- java中字符串String 转 int(转)
java中字符串String 转 int String -> int s="12345"; int i; 第一种方法:i=Integer.parseInt(s); 第二种方法 ...
- std::string和int类型的相互转换(C/C++)
字符串和数值之前转换,是一个经常碰到的类型转换. 之前字符数组用的多,std::string的这次用到了,还是有点区别,这里提供C++和C的两种方式供参考: 优缺点:C++的stringstream智 ...
随机推荐
- MinerThreadPool.java 线程池
MinerThreadPool.java 线程池 package com.iteye.injavawetrust.miner; import java.util.concurrent.Blocking ...
- C++ 仿函数/函数指针/闭包lambda
在上一篇文章中介绍了C++11新引入的lambda表达式(C++支持闭包的实现),现在我们看一下lambda的出现对于我们编程习惯的影响,毕竟,C++11历经10年磨砺,出140新feature,对于 ...
- ssh连接原理介绍( 无密码连接登录的原理)
SSH(Secure Shell)一种在不安全网络上提供安全远程登录及其它安全网络服务的协议.由客户端和服务端的软件组成的,有两个不兼容的版本分别是:1.x和2.x.(SSH 2.x的客户程序是不能 ...
- log4j的一些配置
a). 新建Java Project>>新建package>>新建java类: b). import jar包(一个就够),这里我用的是log4j-1.2.14.jar, c) ...
- 通过Java进行网页抓取并生成plist创建代码
抓取网页的方法: 抓取网页可以通过正则表达式也可以通过Java. 通过firefox浏览器,安装Firebug来查看网页的源代码. 首先将要抓取的部分保存到本地,步骤如下: 1.在要抓取的位置右键,选 ...
- (十三)UITableView数据模型化
多组数据的TableView的设计方法:每一组用一个模型对象表示. 模型包含了标题数据和行数据的数组,在控制器里包含模型的组来对各个模型进行初始化. 在tableView相应的方法中,从控制器的模型组 ...
- C#之面向对象
话说三国时期,曹操带领百万大军攻打东吴,大军在长江赤壁驻扎,军船连成一片,眼看就要灭掉东吴,统一天下,曹操大悦,于是晏众文武,在酒席间,曹操诗兴大发,不觉吟道:"喝酒唱歌,人生真爽" ...
- 一个小公式帮你轻松将IP地址从10进制转到2进制
网络工程师经常会遇到的一个职业问题:如何分配IP,通过子网如何捕捉某一网段或某台机器?他们甚至能够进行精准的分析和复杂的开发......凡此种种,其实与一些他们头脑中根深蒂固的常识性理论存有某种内在的 ...
- 基于RTMP的实时流媒体的QoE分析
Holly French等人在论文<Real Time Video QoE Analysis of RTMP Streams>中,研究了基于RTMP的实时视频的QoE.在此记录一下. 他们 ...
- STL - 各个容器的使用时机
deque的使用场景:比如排队购票系统,对排队者的存储可以采用deque,支持头端的快速移除,尾端的快速添加.如果采用vector,则头端移除时,会移动大量的数据,速度慢. vector与deque的 ...