Integer.numberOfLeadingZeros() Integer方法: publicstaticintnumberOfLeadingZeros(inti){ //HD,Countleading0's if(i<=0) returni0?32:0; intn=31; if(i>=1<<16){n-=16;i>>>=16;} if(i>=1<<8){n-=8;i>>>=8;} if(i>=1<<4){n-=4;i>>>=4;} if(i>=1<<2){...

TreeMap是一个基于key有序的keyvalue散列表。 map根据其键的自然顺序排序,或者根据map创建时提供的Comparator排序 不是线程安全的 key不可以存入null 底层是基于红黑树实现的 TreeMap的类结构图: 实现了NavigableMap接口,NavigableMap又实现了Map接口,提供了导航相关的方法。 继承了AbstractMap,该方法实现Map操作的骨干逻辑。 实现了Cloneable接口,标记该类支持clone方法复制 实现了Serializable接口,标记该类支持序列化 构造方法 TreeMap()//使用键的自然排序构造一个新的空...

Python简易HTTP服务器(http.server) http.server是socketserver.TCPServer的子类,它在HTTP套接字上创建和监听,并将请求分派给处理程序。 Python3内置标准模块。通过执行如下命令创建一个最简单的HTTP服务器: python-mhttp.server服务器默认监听端口是8000 python-mhttp.server9000支持自定义端口号 python-mhttp.server--bind127.0.0.1服务器默认绑定到所有接口,可以通过-b/--bind指定地址,如本地主机。 python-mhttp.server--dire...

str面试题01.06.字符串压缩 base7.整数反转 base9.回文数 base14.最长公共前缀 list20.有效的括号 str28.实现strStr() base38.外观数列 str53.最大子序和 str58.最后一个单词的长度 list66.加一 base118.杨辉三角 base119.杨辉三角II base121.买卖股票的最佳时机 base168.Excel表列名称 list169.多数元素 base223.矩形面积 str344.反转字符串 str387.字符串中的第一个唯一字符 base412.FizzBuzz base414.第三大的数 str415.字符串相加...

  1Hh2sdYQZd4C   2023年11月02日   23   0   0 重复元素链表字符串leetcode

https://github.com/felinx/jieba "结巴"中文分词 一、jieba classTokenizer(object):分词器 defcut(self,sentence,cut_all=False,HMM=True,use_paddle=False): """ Themainfunctionthatsegmentsanentiresentencethatcontains Chinesecharactersintoseparatedwords. Parameter: sentence:Thestr(unicode)tobesegmented. cut_all:Mod...

  1Hh2sdYQZd4C   2023年11月02日   66   0   0 自定义Python信息工程paddle

21.合并两个有序链表 方法一:递归 python classSolution: defmergeTwoLists(self,l1:ListNode,l2:ListNode)->ListNode: ifnotl1:returnl2 ifnotl2:returnl1 ifl1.val<=l2.val: l1.next=self.mergeTwoLists(l1.next,l2) returnl1 else: l2.next=self.mergeTwoLists(l1,l2.next) returnl2 ifl1andl2: ifl1.val>l2.val: l...

1480.一维数组的动态和 classSolution: defrunningSum(self,nums:List[int])-&gt;List[int]: foriinrange(1,len(nums)): nums[i]+=nums[i-1] returnnums return[sum(nums[:i+1])foriinrange(len(nums))] returnaccumulate(nums) <!-本文包含:- <!--

1078.Bigram分词 classSolution: deffindOcurrences(self,text:str,first:str,second:str)-&gt;List[str]: x=text.split() res=[] whilex: iffirstinx: idx=x.index(first) ifidx+2&lt;len(x)andx[idx+1]second: res.append(x[idx+2]) x=x[idx+1:] returnres classSolution: deffindOcurrences(self,text:str,first...

  1Hh2sdYQZd4C   2023年11月02日   48   0   0 其他pythonList其他Listpython

16.最接近的三数之和 方法一:三重循环超时 暴力枚举时间复杂度O(n3)O(n^3)O(n3)。 classSolution: defthreeSumClosest(self,nums:List[int],target:int)-&gt;int: n=len(nums) res=inf foriinrange(n-2): forjinrange(i+1,n-1): forkinrange(j+1,n): s=nums[i]+nums[j]+nums[k] ifabs(res-target)&gt;abs(targets): res=s returnres 方法二:排序+双指...

881.救生艇 classSolution: defnumRescueBoats(self,people:List[int],limit:int)-&gt;int: people.sort() n=len(people) l,r=0,n-1 whilel&lt;=r: ifpeople[l]+people[r]&lt;=limit: l+=1 r-=1 returnn1r <!-本文包含:- <!--

  1Hh2sdYQZd4C   2023年11月02日   45   0   0 其他pythonList其他Listpython

一、关键字 1、return2、if3、elif4、else5、for6、while 二、内置函数 1、print()2、max()3、min()4、len()5、range()6、enumerate() 4、input()5、type()6、int() 三、运算符 +///=+=-=&gt;&gt;=%三目运算符in成员运算符 1、算数运算符 +加数字与字符串拼接 减 乘数字与字符串重复 /除返回浮点数 %取模返回除法的余数奇偶判断 幂次 //整除返回商的整数部分,向下取整数,注意:-10//3,出现负数时的情况 只要参与运算的有浮点数,返回类型为float。 2、比较运算符 比较值...

  1Hh2sdYQZd4C   2023年11月02日   64   0   0 Java学习赋值运算符运算符python

849.到最近的人的最大距离 classSolution{ publicintmaxDistToClosest(int[]seats){ inti=0,n=seats.length,j=n1; while(seats[i]0)i; intres=i; while(seats[j]0)j--; res=Math.max(res,nj1); for(intk=i+1;k&lt;=j;k){ if(seats[k]1){ res=Math.max(res,(ki)/2); i=k; } } returnres; } } 855.考场就座 classExamRoom{ intn; TreeSe...

  1Hh2sdYQZd4C   2023年11月02日   93   0   0 Javai++Math取整

第343场周赛 2663.字典序最小的美丽字符串 长度为m的回文串必然包含长度为m−2的回文串。所以只需要保证答案不包含长度为2或者长度为3的回文串。 换句话说,不能出现s[i]=s[i−1]以及s[i]=s[i−2]。这个性质十分重要,它意味着只需要判断s[i]左侧的两个字母。 s[i]与其右边的两个字母s[i+1]和s[i+2]呢?交给i+1和i+2来判断。 既然要字典序最小,那么修改的位置越靠右越好。下面把s看成一个k进制数来理解。也就是说,‘a’视作0,‘b’视作1,依此类推。 例如s=dacd,先把末尾的s[3]=d加一,进位得到dada。但这样前三个字母和后三个字母都形成了回文串...

  1Hh2sdYQZd4C   2023年11月02日   125   0   0 List回文串算法leetcode动态规划

2591.将钱分给最多的儿童 classSolution: defdistMoney(self,money:int,children:int)-&gt;int: ifmoney&lt;children:return-1 money-=children每人至少1美元 res=min(money//7,children)初步分配,让尽量多的人分到8美元 money-=res7 children-=res if(children0andmoney&gt;0)or(children1andmoney3): res-=1 returnres 2706.购买两块巧克力 算法:最小值与次最小值 cl...

  1Hh2sdYQZd4C   2023年11月02日   44   0   0 List最小值前缀和开发语言python

控制结构语句循环语句 一、for 求1到100的和 sum=0用于记录和 foriinrange(1,101): sum+=i print(sum) 二、while whileTrue: age=input('请输入年龄:') ifnotage:直接回车age='',notage是True continue elifage.isdigit(): print(f'十年后,你{int(age)+10}岁!') break else: print('你输入的类型错误。') 三、break和continue break结束当前循环continue结束本次循环,继续判断条件执行下一次循环。...

  1Hh2sdYQZd4C   2023年11月02日   62   0   0 Listgit循环语句开发语言python

基础语法测试 1、注册Leetcode2、学会使用平台 223.矩形面积 知识点:return,max(),.min() classSolution: defcomputeArea(self,ax1:int,ay1:int,ax2:int,ay2:int,bx1:int,by1:int,bx2:int,by2:int)-&gt;int: a=(ax1ax2)(ay1ay2) b=(bx2bx1)(by2by1) w=min(ax2,bx2)max(ax1,bx1) h=min(ay2,by2)max(ay1,by1) c=max(w,0)max(h,0) returna+bc 数学技巧...

  1Hh2sdYQZd4C   2023年11月02日   42   0   0 linux迭代数据库python

Python内置模块re 正则表达式(RegularExpression简写regex)是一种字符串匹配的模式(pattern)。 一、匹配原理 正则表达式是由正则表达式引擎编译执行的。 1、预编译(pre-usecompile) 通过re.compile(pattern)预编译返回Pattern对象 通过re.match(pattern,text)即用编译,虽然也会有缓存Pattern 对象,但是每次使用都需要去缓存中取出,比预编译多一步取操作。 importre 将正则表达式'hello'编译成Pattern对象 pattern=re.compile('hello') print(...

  1Hh2sdYQZd4C   2023年11月02日   42   0   0 字符串正则表达式python
关注 更多

空空如也 ~ ~

粉丝 更多

空空如也 ~ ~