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 · 95 阅读 · 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 · 99 阅读 · 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 · 106 阅读 · 0 评论 -
初级训练营—移动零
一、问题描述 二、解题思路 先把出现的0删掉,再在数组的后面加0 class 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 · 80 阅读 · 0 评论 -
初级训练营—加一
一、问题描述 二、解题思路 先把数组提取出来,换成整数,然后通过除法运算将整数转换成数组 class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ n = 0 ...原创 2020-03-31 10:42:57 · 208 阅读 · 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 · 78 阅读 · 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 · 254 阅读 · 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 · 155 阅读 · 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 · 59 阅读 · 0 评论 -
初级训练营—买卖股票的最佳时机 II
一、题目描述 二、解题思路 第二天的股票价格必须比第一天的价格多才能赚钱,相当于以第一天的价格买进,第二天的价格卖出 设 tmp 为第 i-1日买入与第 i 日卖出赚取的利润,即 tmp=prices[i] - prices[i-1]; 当该天利润为正 tmp>0,则将利润加入总利润 profit;当 tmp<=0, 直接跳过; 遍历完成后,返回总利润 profit class ...原创 2020-03-30 13:43:13 · 134 阅读 · 0 评论 -
初级训练营—删除排序数组中的重复项
一、题目 二、解题思路 使用两个指针 i 和 j class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: retu...原创 2020-03-30 11:51:14 · 65 阅读 · 0 评论