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智 ...
随机推荐
- Linux IPC实践(3) --具名FIFO
FIFO具名/命名管道 (匿名)管道应用的一个限制就是只能在具有共同祖先(具有亲缘关系)的进程间通信. 如果我们想在不相关的进程之间交换数据,可以使用FIFO文件来做这项工作,它经常被称为命名管道;命 ...
- 《java入门第一季》之面向对象静态内部类和非静态内部类的区别
很感谢在内部类章节,"开心阳"先生给与的建议.使用静态内部类.这里就简单说一下静态内部类的使用. package com.devin; public class MyMain{ p ...
- Swift基础之UIButton
//设置全局变量,将下面的替换即可 //var myButton = UIButton(); //系统生成的viewDidLoad()方法 override func viewDid ...
- how tomcat works 读书笔记(一)----------一个简单的web服务器
http协议 若是两个人能正常的说话交流,那么他们间必定有一套统一的语言规则<在网络上服务器与客户端能交流也依赖与一套规则,它就是我们说的http规则(超文本传输协议Hypertext tran ...
- ITU-T Technical Paper: IP服务性能模型
本文翻译自ITU-T的Technical Paper:<How to increase QoS/QoE of IP-based platform(s) to regionally agreed ...
- GDI+ 读取jpg图片每个像素的值
// 读取jpg图像像素rgb值.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #in ...
- Linux中find的使用(转)
本文转自:迷途花开 另一值得参考的是吴秦先生的博文linux中强大且常用命令:find.grep. find命令用于查找文件和目录,任何位于参数之前的字符串都将被视为欲查找的目录. find 可以指定 ...
- PS 滤镜——极坐标变换到平面坐标
%%% 极坐标到平面坐标 clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorith ...
- TCP连接建立系列 — TCP选项解析
本文主要分析:在收到客户端的SYN包时,服务器端是如何解析它所携带的TCP选项,并结合本端情况决定是否予以支持. 内核版本:3.6 Author:zhangskd @ csdn blog 概述 收到客 ...
- 总结:如何驱动DS18B20温度传感器
DS18B20时序分析: 以下是STM32的驱动代码: #include "bsp_ds18b20.h" static void DS18B20_GPIO_Config(void) ...