
leetcode初级训练营
默默努力的人
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
初级训练营—整数反转
一、问题描述二、解题思路class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ flag=1 if x<0: flag=-1 x=ab...原创 2020-03-31 20:23:10 · 135 阅读 · 0 评论 -
初级训练营—旋转图像
一、问题描述二、解题思路class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. ...原创 2020-03-31 15:58:08 · 142 阅读 · 0 评论 -
初级训练营—两数之和
一、问题描述二、思路温习class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ if not nums...原创 2020-03-31 11:57:08 · 450 阅读 · 0 评论 -
初级训练营—移动零
一、问题描述二、解题思路先把出现的0删掉,再在数组的后面加0class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] :rtype: None Do not return anything, modify nums in-place in...原创 2020-03-31 11:25:21 · 116 阅读 · 0 评论 -
初级训练营—加一
一、问题描述二、解题思路先把数组提取出来,换成整数,然后通过除法运算将整数转换成数组class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ n = 0 ...原创 2020-03-31 10:42:57 · 250 阅读 · 0 评论 -
初级训练—两个数组的交集 II
一、题目描述二、答题思路class Solution(object): def intersect(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ re...原创 2020-03-30 22:58:07 · 113 阅读 · 0 评论 -
初级训练营—只出现一次的数字
一、题目描述二、解题思路class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ dic={} for i in nums: if ...原创 2020-03-30 21:53:41 · 424 阅读 · 0 评论 -
初级训练营—存在重复
一、问题描述二、思路—用字典的形式class Solution(object): def containsDuplicate(self, nums): """ :type nums: List[int] :rtype: bool """ numDic={} for i in nums: ...原创 2020-03-30 21:13:46 · 211 阅读 · 0 评论 -
初级训练营—旋转数组
一、问题二、解题思路class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: None Do not return anything, modify nums in-place in...原创 2020-03-30 15:03:24 · 98 阅读 · 0 评论 -
初级训练营—买卖股票的最佳时机 II
一、题目描述二、解题思路第二天的股票价格必须比第一天的价格多才能赚钱,相当于以第一天的价格买进,第二天的价格卖出设 tmp 为第 i-1日买入与第 i 日卖出赚取的利润,即 tmp=prices[i] - prices[i-1];当该天利润为正 tmp>0,则将利润加入总利润 profit;当 tmp<=0, 直接跳过;遍历完成后,返回总利润 profitclass ...原创 2020-03-30 13:43:13 · 165 阅读 · 0 评论 -
初级训练营—删除排序数组中的重复项
一、题目二、解题思路使用两个指针 i 和 jclass Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: retu...原创 2020-03-30 11:51:14 · 116 阅读 · 0 评论