6 Z 字形变换(题目链接

class Solution:
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
lists = []
for i in range(numRows):
lists.append('')
numMids = numRows - 2
if numMids < 0:
numMids = 0
for i_s in range(len(s)):
rest = i_s % (numMids + numRows)
if rest < numRows:
lists[rest] = ''.join([lists[rest], s[i_s]])
else:
lists[numMids + numRows - rest] = ''.join([lists[numMids + numRows - rest], s[i_s]])
s_result = ''.join(lists)
return s_result

7.整数反转(题目链接

class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
y = 0
z = 1
if x < 0:
z = -1
x = -x
while x != 0:
item = x % 10
x = x // 10
if 2147483647 - 10 * y <= item:
return 0
y = y * 10 + item
return y*z

8.字符串转换整数 (atoi)(题目链接

class Solution:
def myAtoi(self, str: 'str') -> 'int':
sign = 0
num = 0
for i in str:
if sign == 0 and i == ' ':
continue
elif sign == 0 and i == '-':
sign = -1
elif sign == 0 and i == '+':
sign = 1
elif i in ['','','','','','','','','','']:
if (sign == 1 or sign == 0) and (2147483647 - int(i)) // 10 < num:
return 2147483647
elif sign == -1 and (2147483648 - int(i)) // 10 < num:
return -2147483648
else:
if sign == 0:
sign = 1
flag = 1
num = num * 10 + int(i)
else:
break
if sign == 0:
return num
return sign * num

LeetCode 刷题记录(6-10题)的更多相关文章

  1. Leetcode第1题至第10题 思路分析及C++实现

    笔者按照目录刷题,对于每一道题,力争使用效率最高(时间复杂度最低)的算法,并全部通过C++代码实现AC.(文中计算的复杂度都是最坏情况复杂度) 因为考虑到大部分读者已经在Leetcode浏览过题目了, ...

  2. LeetCode 刷题记录(1-5题)

    1 两数之和(题目链接) class Solution: # 一次哈希法 def twoSum(self, nums, target): """ :type nums: ...

  3. Leetcode刷题记录(python3)

    Leetcode刷题记录(python3) 顺序刷题 1~5 ---1.两数之和 ---2.两数相加 ---3. 无重复字符的最长子串 ---4.寻找两个有序数组的中位数 ---5.最长回文子串 6- ...

  4. leetcode刷题记录--js

    leetcode刷题记录 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但 ...

  5. LeetCode刷题模板(1):《我要打10个》之二分法

    Author       :  叨陪鲤 Email         : vip_13031075266@163.com Date          : 2021.01.23 Copyright : 未 ...

  6. leetcode刷题--两数之和(简单)

    一.序言 第一次刷leetcode的题,之前从来没有刷题然后去面试的概念,直到临近秋招,或许是秋招结束的时候才有这个意识,原来面试是需要刷题的,面试问的问题都是千篇一律的,只要刷够了题就差不多了,当然 ...

  7. LeetCode刷题指南(字符串)

    作者:CYC2018 文章链接:https://github.com/CyC2018/CS-Notes/blob/master/docs/notes/Leetcode+%E9%A2%98%E8%A7% ...

  8. LeetCode刷题总结-数组篇(中)

    本文接着上一篇文章<LeetCode刷题总结-数组篇(上)>,继续讲第二个常考问题:矩阵问题. 矩阵也可以称为二维数组.在LeetCode相关习题中,作者总结发现主要考点有:矩阵元素的遍历 ...

  9. C#LeetCode刷题-动态规划

    动态规划篇 # 题名 刷题 通过率 难度 5 最长回文子串   22.4% 中等 10 正则表达式匹配   18.8% 困难 32 最长有效括号   23.3% 困难 44 通配符匹配   17.7% ...

随机推荐

  1. Java类只加载一次的情况

    一个类只加载一次: 调用Java命令. 创建对象时 访问静态成员时 Class.forName("包名.类名")

  2. memcached redis 本质区别是功能多少

    功能: 1.memcached 数据类型比较单一,数据淘汰策略单一,功能简单 2.redis 数据类型比较全面, 数据淘汰策略比较多,功能较强 有持久化能力,可以持久存储少量数据(数据量不会大于本机内 ...

  3. python实现图书管理系统

    # 用户注册 def logon(): print("欢迎来到图书管理系统注册页面~") username = input("请输入用户名:") if len( ...

  4. Spring和MyBatis的集成

    Spring和MyBatis的整合   1. Spring和各个框架的整合 Spring目前是JavaWeb开发中最终的框架,提供一站式服务,可以其他各个框架整合集成 Spring整合方案 1.1.  ...

  5. [Algo] 292. String Abbreviation Matching

    Word “book” can be abbreviated to 4, b3, b2k, etc. Given a string and an abbreviation, return if the ...

  6. webfrom 控件

    服务器基本控件: button: text属性 linkbutton:text属性,它是一个超链接模样的普通button hyperlink: navigateurl:链接地址,相当于<a> ...

  7. IDEA中的常用插件安装以及使用的介绍

    IDEA中的lombok插件安装以及各注解的详细介绍 Grep Console 当你密密麻麻一大片的日志,去查看起来,很容易看花眼:这个工具正好解决了这个痛点,可以说它就是 IDEA 自带 Conso ...

  8. TPO5-2 The Origin of Pacific Island People

    Contrary to the arguments of some (that much of the pacific was settled by Polynesians accidentally ...

  9. servletHomeWork

    2. http全称是什么? 超文本传输协议(HTTP, HyperText Transfer Protocol)是互联网上应用为最广泛的一种网络协议. 3.http协议是无状态的协议是什么意思?请说明 ...

  10. 搭建WordPress个人博客

    1. 准备LNMP环境 LNMP 是 Linux.Nginx.MySQL 和 PHP 的缩写,是 WordPress 博客系统依赖的基础运行环境.我们先来准备 LNMP 环境 安装Nginx 使用 y ...