1 很吵请安青争

尚未进行身份认证

暂无相关描述

等级
TA的排名 3k+

LC.293. Flip Game ,LC.294. Flip Game II

294.FlipGameclassSolution(object):defgeneratePossibleNextMoves(self,s):""":types:str:rtype:List[str]"""return[s[:i]+"--"+s[i+2:]fori...

2019-09-15 07:45:54

LC.394. Decode String

classSolution1(object):defdecodeString(self,s):"""使用stack没遇到一个右括号就将其括住的部分释放出来"""stack=[]forcharins:ifchar==']':...

2019-09-15 01:01:36

二叉索引树 (英语:Binary Indexed Tree)

二叉索引树(英语:BinaryIndexedTree)二叉索引树又叫数目状态数组,它的存储结构是数组,但是逻辑结构是树。可以想一下堆排序的时候,我们虽然用的是数组存数,但是其逻辑上是一棵完全二叉树。为什么会引入这个结构?对于下面的问题:给定一个数组,让我们求下标在(start,end]这个区间的子数组的和,我们的做法一般是先求一个sumer数组,sumer[i]表示sum(array...

2019-09-14 23:27:12

LC.243. Shortest Word Distance

classSolution1(object):defshortestDistance(self,words,word1,word2):"""转化为两个有序数组求最小双指针不断将两元素移动到一起"""dictionary={}foriinrange(len(wo...

2019-09-14 22:40:53

LC.1056. Confusing Number, LC.246. Strobogrammatic Number

classSolution(object):defconfusingNumber(self,N):"""1.判断字符是否可选择2.判断旋转是否不变"""rotate={'0':'0','1':'1','6':'9','8':'8','9':'6'}N=li...

2019-09-14 21:26:59

1064. Fixed Point

classSolution1(object):deffixedPoint1(self,A):"""直接循环"""foriinrange(len(A)):ifA[i]==i:returnireturn-1...

2019-09-14 21:19:49

LC.1065. Index Pairs of a String

classSolution(object):defindexPairs(self,text,words):"""利用find(word,start,end)函数时间复杂度为O(#words*len(text)"""result=[]forwordin...

2019-09-14 20:25:58

LC.1085. Sum of Digits in the Minimum Number

classSolution1(object):defsumOfDigits(self,A):"""求最小min即可求和的奇偶性可以用异或运算,并且只需要关注最后一位"""number=min(A)result=0fornuminlist(s...

2019-09-14 09:52:02

LC.1150. Check If a Number Is Majority Element in a Sorted Array

classSolution1(object):defisMajorityElement(self,nums,target):"""oneline,摩尔投票算法O(n)"""returnsum([-1ifx!=targetelse1forxinnums])>0clas...

2019-09-14 09:18:13

LC.1154. Day of the Year

classSolution:defdayOfYear(self,date:str)->int:"""比起根据日期求weekday的吉姆拉尔森公式,这道题很常规,判断个闰年即可"""month_day=[31,28,31,30,31,30,31,31,30,31,30,3...

2019-09-14 08:24:26

LC.1160. Find Words That Can Be Formed by Characters

classSolution1(object):defcountCharacters(self,words,chars):"""straightforword的方法,char数组记录,每次遍历两遍word,count加和count减"""result=0char_array=...

2019-09-14 08:13:40

LC.1134. Armstrong Number

classSolution1(object):defisArmstrong(self,N):""":typeN:int:rtype:bool"""N_=list(map(int,list(str(N))))N_=sum(map(lambdax:pow(x,...

2019-09-14 07:33:58

LC.1086. High Five

classSolution(object):defhighFive(self,items):"""这道题也可以转化为前K大问题,分组后利用快排的思想"""defgetK(array,start,end,K):ifstart>end:...

2019-09-13 23:41:31

LC.1133. Largest Unique Number

classSolution(object):deflargestUniqueNumber(self,A):"""排序然后找到第一个不重复的数"""A.sort(reverse=True)print(A)left,index=0,0whileind...

2019-09-13 21:55:35

LC.1099. Two Sum Less Than K

classSolution(object):deftwoSumLessThanK(self,A,K):"""twopoint问题"""A.sort()left,right=0,len(A)-1result=-1whileleft&lt...

2019-09-13 21:39:08

LC.1160. Find Words That Can Be Formed by Characters

classSolution1(object):defnumSmallerByFrequency(self,queries,words):"""直接统计"""fromcollectionsimportCounterdefhelper(string):stri...

2019-09-13 21:16:55

LC.1175. Prime Arrangements

两种筛法做质数筛选classSolution(object):defnumPrimeArrangements(self,n):"""朴素筛法,又叫埃氏筛法,时间复杂度O(nlogn)线性筛法,又叫欧拉筛法,时间复杂度O(n)"""defnative_filter1(n):...

2019-09-13 19:53:55

LC.1176. Diet Plan Performance

classSolution(object):defdietPlanPerformance(self,calories,k,lower,upper):"""easyslidewindow注意题目的意思,连续的window(sequence之间有重叠)"""calories=[...

2019-09-13 18:38:39

LC.1180. Count Substrings with Only One Distinct Letter

classSolution:defcountLetters(self,S:str)->int:"""统计连续相同字符出现的次数即可对于长度为n的相同字符的字符串,他有1+2+..n个子串"""defsum_n(n):return(n+1)*n/...

2019-09-13 18:28:56

LC.1151. Minimum Swaps to Group All 1's Together

classSolution(object):defminSwaps(self,data):"""slidewindow问题首先统计有多少个1,假如有K个,弄一个长度为K的滑动窗口求滑动窗口内最少的0"""K=sum(data)cur_0=K...

2019-09-13 18:13:07

查看更多

勋章 我的勋章
  • 专栏达人
    专栏达人
    授予成功创建个人博客专栏的用户。专栏中添加五篇以上博文即可点亮!撰写博客专栏浓缩技术精华,专栏达人就是你!
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 勤写标兵Lv4
    勤写标兵Lv4
    授予每个自然周发布9篇以上(包括9篇)原创IT博文的用户。本勋章将于次周上午根据用户上周周三的博文发布情况由系统自动颁发。