自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 资源 (1)
  • 收藏
  • 关注

原创 Leetcode 567. Permutation in String 双指针

Given two stringss1ands2, write a function to return true ifs2contains the permutation ofs1. In other words, one of the first string's permutations is thesubstringof the second string.Exa...

2020-01-31 22:27:41 128

原创 Leetcode 903. Valid Permutations for DI Sequence DI序列的个数

We are givenS, a lengthnstring of characters from the set{'D', 'I'}. (These letters stand for "decreasing" and "increasing".)Avalid permutationis a permutationP[0], P[1], ..., P[n]of integer...

2020-01-31 16:57:54 262

原创 Leetcode Perfect Squares 拉格朗日四平方

Given a positive integern, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum ton.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Example...

2020-01-30 16:57:03 185

原创 Leetcode 1147. Longest Chunked Palindrome Decomposition

Return the largest possibleksuch that there existsa_1, a_2, ..., a_ksuch that:Eacha_iis a non-empty string; Their concatenationa_1 + a_2 + ... + a_kis equal totext; For all1 <= i <...

2020-01-30 11:07:43 192

原创 python str ord chr 字符串赋值 trailing comma 尾巴逗号

Here’re examples:a = '12y'# ch = ord(a) TypeError: ord() expected a character, but string of length 3 foundch = chr(ord(a[0])+1)print(ch) #2ch = chr(ord(a[2])+1)print(ch) #z

2020-01-29 17:30:20 601

原创 Leetcode Super Palindromes Next Palindrome

Let's say a positive integer is asuperpalindromeif it is a palindrome, and it is also the square of a palindrome.Now, given two positiveintegersLandR(represented as strings), return the numbe...

2020-01-29 16:49:06 168

原创 leetcode Word Subsets

We are given two arraysAandBof words. Each word is a string of lowercase letters.Now, say thatwordbis a subset of wordaif every letter inboccurs ina,including multiplicity. For exampl...

2020-01-27 22:43:19 127

原创 Python collections Counter defaultdict itertools permutations functools lru_cache reduce

见例子:from collections import Counterstr = './root//users/yanti/'res = str.split('/')print(res)a = Counter('leetcode')print(a) #Counter({'e': 3, 't': 1, 'd': 1, 'o': 1, 'l': 1, 'c': 1})print(...

2020-01-27 21:21:45 153

原创 牛顿法 一阶导 二阶导 平方根 Sqrt

以前牛顿法的印象就是Hessen矩阵,二阶导,今天忽然发现好像求平方根大家玩得是一阶导,后来仔细推导了一下发现一阶导 二阶导都是牛顿法,从泰勒展开说起f(x)=f(xn)+f′(xn)(x−xn)+12f′′(xn)(x−xn)2f(x)=f(x_n)+f'(x_n)(x-x_n)+\frac{1}{2}f''(x_n)(x-x_n)^2f(x)=f(xn​)+f′(xn​)(x−xn​)+...

2020-01-18 23:10:01 958 1

转载 堆,赢者树,败者树的区别与联系

今天做LeetCode的23. Merge k Sorted Lists这道题的时候,遇到的这个问题。这道题本质上就是一个多路归并的问题,而这道题主要就是考察多路归并时候的选择问题。按照之前本科上课学的,最好的办法就是用竞赛树(败者树),可是我嫌麻烦就用堆来做了,也顺利能过。所以就想到,堆,赢者树,败者树到底有什么区别呢?于是找了一些资料看了一下,在这里总结一下相同点首先它们三个的相同点...

2020-01-17 10:38:17 803

原创 Leetcode Lexicographical Numbers 数字字典序列输出

Given an integern, return 1 -nin lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input size m...

2020-01-13 22:51:40 300

原创 Leetcode 440 K-th Smallest in Lexicographical Order n叉树快速按层遍历

Given integersnandk, find the lexicographically k-th smallest integer in the range from1ton.Note: 1 ≤ k ≤ n ≤ 109.Example:Input:n: 13 k: 2Output:10Explanation:The lexicographical...

2020-01-13 20:51:36 147

原创 Leetcode Path with Maximum Gold

In a gold minegridof sizem * n,each cell in this mine has an integer representing the amount of goldin that cell,0if it is empty.Return the maximum amount of gold youcan collect under the co...

2020-01-12 17:23:52 177

原创 Python reverse list 局部反转 逆向切片 多维 slice list拼接

需要牢记几点:range(a,b,c)和a:b:ca:b:ca:b:c的含义是一样的,但是list的下标只能用a:b:ca:b:ca:b:c,其中c是步长reverse和reversed的区别是有没有返回值,类似于sort和sorted的区别如果逆着slice,len(arr)−1:−1:−1len(arr)-1:-1:-1len(arr)−1:−1:−1要返回空,因为-1在slice里被...

2020-01-12 10:09:49 1841

原创 leetcode Smallest Range II

Given an array A of integers, for each integer A[i] we need to choose either x = -K or x = K, and add x to A[i] (only once).After this process, we have some array B.Return the smallest possible diff...

2020-01-07 16:19:33 169

原创 编程之美 判断点是否在多边形内 射线法

顾名思义,假设要判断点(x∗,y∗)(x^*,y^*)(x∗,y∗)是否在多边形内,弄一条射线y=y∗(x>=x∗)y=y^* (x >= x^*)y=y∗(x>=x∗)看这条射线会穿越边奇数次,就是在内;否则,就是不在内。然鹅,这个题目有5种情况:(x∗,y∗)(x^*,y^*)(x∗,y∗) 在多边形的边上,算在内,需要特殊考虑(x∗,y∗)(x^*,y^*)(x∗...

2020-01-04 15:43:25 263

转载 编程之美-金刚坐飞机问题

文章背景编程之美 4.1 “金刚坐飞机问题”的问题2,难度比问题1大很多。编程之美的官方解法,包括原理分析、概率公式、推导过程等,感觉阐述不够详细,没有完全读懂。搜索一下 “金刚坐飞机”,参考了几个很不错的分析,得到一个自己觉得比较完整的答案。仔细审题首先,仔细审题,有两个细节需要搞清楚:飞机上总共有多少座位?N?N+1?还是更多?从问题1的官方解答看,...

2020-01-01 18:33:52 260

原创 Python heapq LeetCode 692. Top K Frequent Words

默认最小在最前,这个和sorted一样,没有reverse,但是可以用tuple来玩heapq是module(文件),所以importheapq.heappush是直接调用这个module最外层的函数import heapqh1 = []heapq.heappush(h1, (5, 'write code'))heapq.heappush(h1, (7, 'release p...

2020-01-01 00:06:22 216

空空如也

空空如也

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

TA关注的人

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