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. Excel VBA发送Email时自动允许Outlook安全对话框

    在Outlook的宏安全性设置如果选择了“为所有宏提供通知” 并且,在[编程访问]中选择了“总是向我发出警告” 在其他VBA中创建邮件过程中,如果修改Recipients或者执行Send方法,都会弹出 ...

  2. MySql数据库,查询数据导出时会出现重复的记录(数据越多越明显)

    在查询数据时,数据量多的时候,我们会使用分页功能. 每页显示多少数据. 这种情况下,一半看不出什么问题. 而导出数据时,有时就是通过分页的方法,逐步讲数据追加到导出文件中. 当全部数据都导出之后,就有 ...

  3. 第一行代码近期bug及解决

    Android学习笔记(5)----启动 Theme.Dialog 主题的Activity时程序崩溃的解决办法https://www.cnblogs.com/dongling/p/6476308.ht ...

  4. Ubuntu下安装Docker,及Docker的一些常用命令操作

    1.什么是 Docker         Docker 是一个开源项目,Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案.         Docker 的基础是 Linux 容器(LXC ...

  5. 线段树、最短路径、最小生成树、并查集、二分图匹配、最近公共祖先--C++模板

    线段树(区间修改,区间和): #include <cstdio> #include <iostream> #include <cstring> using name ...

  6. python代码实现购物车(django的redis与vue)

    安装模块 pip install django-redis 后端代码 # 购物车 class CartView(APIView): # 初始化函数 def __init__(self): self.c ...

  7. $.post系统登录校验

    AJAX方式:$.post系统登录校验 https://blog.csdn.net/woshisangsang/article/details/66560238?utm_source=blogxgwz ...

  8. UI自动化(selenium+python)之元素定位的三种等待方式

    前言 在UI自动化过程中,常遇到元素未找到,代码报错的情况.这种情况下,需要用等待wait. 在selenium中可以用到三种等待方式即sleep,implicitly_wait,WebDriverW ...

  9. Windows环境搭建 face_recognition,dlib

    文章参考:https://blog.csdn.net/hongbin_xu/article/details/76284134 文章参考:https://blog.csdn.net/weixin_404 ...

  10. [LC] 314. Binary Tree Vertical Order Traversal

    Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bott ...