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. 参考JDK1.8源码,自己写一个类似于ArrayList的动态数组

    1. ArrayList的基本实现原理 ArrayLiST其内部用一个普通数组来存储数据,当此数组不够容纳新添加的元素的时候,则创建一个更大长度的新数组,并将原来数组中的元素复制到新数组中. 2.Ar ...

  2. Methyl-SeqDNA的甲基化图谱|DNase I-Seq|ChIP-Seq|3C-Seq|

    生物医学大数据 Methyl-SeqDNA的甲基化图谱 DNase I-Seq全基因组染色质DNA的开放程度.非基因编码区的调控元件的分布 DNase I高敏感位点:基因处于转录活性状态时,其染色质结 ...

  3. deque & list

    deque 双向队列 它也是采用动态数组的方式来管理的提供了随机数组 和vector的区别 1.deque头尾两端可以开放,能够进行快速的插入和删除(vector只能在尾部进行快速的插入和删除) 2. ...

  4. 如何选择开源项目的license

    https://choosealicense.com/ http://www.csdn.net/article/2013-07-16/2816249-Github-Open-Source-Licens ...

  5. 论文翻译——Deep contextualized word representations

    Abstract We introduce a new type of deep contextualized word representation that models both (1) com ...

  6. Jmeter学习前提:Jmeter安装

    一.Jmeter下载 1. 前提:已经安装 jdk8+ 1.1 JDK下载 a. 进入jdk8+下载地址:https://www.oracle.com/technetwork/java/javase/ ...

  7. 爬虫笔记(十)——学会使用Fiddler

    Fiddler是一个常见的抓包分析软件,同时我们可以利用它详细地对HTTP请求进行分析,并模拟对应的HTTP请求. 为什么使用Fiddler软件? 网络爬虫是自动爬取网页的程序,在爬取的过程中必然涉及 ...

  8. Java--面向对象三大特征-->封装、继承、多态

    简介 在面向过程当中只有存在封装(对功能的封装 例如c语言中的函数),而在面向对象中才存在这三大特性. 继承 -->inheritance 1.子类可以从父类继承属性和方法(除去父类私有化的方法 ...

  9. Codeforces 558E A Simple Task(计数排序+线段树优化)

    http://codeforces.com/problemset/problem/558/E Examples input 1 abacdabcda output 1 cbcaaaabdd input ...

  10. 自定义控件 监控宿主activity的生命周期

    使用不显示的fragment来监控activity生命周期,fragment生命周期基本上跟随宿主activity变化.我们通过fragment的生命周期就可以知到activity的生命周期 我们自定 ...