自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(8)
  • 收藏
  • 关注

原创 数学

常用算法1 << 1 = 1 * 2对于任意一个数字总是可以用2^x + 2^y + ... + 1 来表示

2021-05-26 13:50:01 60

原创 二分法

二分法基本模版class Solution: # @param nums: The integer array # @param target: Target number to find # @return the first position of target in nums, position start from 0 def binarySearch(self, nums, target): if len(nums) == 0:

2021-05-26 12:25:05 173

原创 BackTracking Problems

Permutation IIGiven a collection of numbers,nums,that might contain duplicates, returnall possible unique permutationsin any order.有重复数字: [1,2,1]sort, 在前一个相同数字被选之前,不能选当前数字,否则会出现 1pi, 1 == 1, 1pi的情况Subset IIGiven an integer arraynumsthat may...

2021-05-20 14:41:36 72

原创 Spiral Matrix I && II

simulation, (i, j) 来记录每一层的起始坐标坐标变换来traverse当前坐标最后一个环只有一行或者一列,可以跳出循环class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: # (i, j) is the start of traveral coordinates # (p, q) is the current coo

2021-05-10 09:56:29 53

原创 Subarray 问题

Subarray 问题常用思路1. 从第i个到第j个 subarray 之和 转换成 sum(0,,j) - sum(0,,i)使用典型题目:sum divide by k, sum equal to k,sum multiple of k2. maximum subarray sum / product单一subarray问题,可以思考当1 pass到第i个的时候和已知包含(i-1)个关系,同时维持一个全局变量来记录所有已知的最优解product稍微复杂一点,需要考虑0 reset .

2021-05-10 06:16:38 414

原创 Best Time to buy && sell stock

买卖一次1个变量记录目前已知最便宜,(当前 - 已知最便宜)= 当前最大收益买卖无数次https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii特殊值的处理,如果全部一样的话,其实可以直接initiate peak && valley = prices[0], 这样对于总体的profit是没有变化的~t1 < t2 < t3:buy t1, sell t2 && buy.

2021-05-09 07:19:21 69

原创 Pascal Triangle I && II

Easy manipulation of the triangleThe main idea is to maintian 2 arrays and keeps using the 1st array to store last row information and use it to update/edit the 2nd row results1. prev_array2. curr_array因为需要得知当前array的信息,其实只需要记录上一排array的信息不能只用一个arr

2021-05-04 00:07:18 55

原创 2 Sum / 3 Sum / 4 Sum

1.Two SumGiven an array of integersnumsand an integertarget, returnindices of the two numbers such that they add up totargetYou may assume that each input would haveexactlyone solution, and you may not use thesameelement twiceYou can return...

2021-05-03 13:30:07 129 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除