您的位置:首页 > 娱乐 > 八卦 > 黄骅港一日游必去景点推荐_系统定制开发_十大经典案例_seo搜狗

黄骅港一日游必去景点推荐_系统定制开发_十大经典案例_seo搜狗

2025/3/13 20:44:59 来源:https://blog.csdn.net/MYX_309/article/details/146216963  浏览:    关键词:黄骅港一日游必去景点推荐_系统定制开发_十大经典案例_seo搜狗
黄骅港一日游必去景点推荐_系统定制开发_十大经典案例_seo搜狗

二分查找

双指针查找

无重复数字

lst=[1,15,24,36,78,92,101]
n=int(input())
def binary_search(n,lst):left = 0right = len(lst) - 1while left<=right:mid=(left+right)//2if lst[mid]==n:return midelif lst[mid]<n:left=mid+1elif lst[mid]>n:right=mid-1return -1
print(binary_search(n,lst))

有重复数字

返回第一次出现目标数字的位置

lst=[1,15,15,24,24,36,78,92,101]
n=int(input())
def binary_search(n,lst):left = 0right = len(lst) - 1while left<=right:mid=(left+right)//2if lst[mid]==n:temp=midwhile lst[temp]==n and temp>=0:temp-=1return temp+1elif lst[mid]<n:left=mid+1elif lst[mid]>n:right=mid-1return -1
print(binary_search(n,lst))

移动0

将0移动到末尾

lst=[1,0,0,24,24,0,78,92,101]
for i in lst:if i==0:lst.remove(i)lst.append(0)
print(lst)

旋转字符串

若将a字符串从某位置分隔开并将左边字符串移动到右边字符串后组成新的字符串组成b时返回true

想法非常巧妙,将两个a字符串组在一起,若b是其子串则说明可以分割出来

a="hello"
b="lohel"
def func(a,b):A = a + aif b in A:return Trueelse:return False
print(func(a,b))

判断子序列

如果按照顺序s中的字符可以在t中按照顺序找到,则为子序列

t="hello"
s="elo"
def search(t,s):a=0b=0res=""while b<=(len(s)-1) and a<=(len(t)-1):if s[b]==t[a]:res+=t[a]b+=1a+=1if res==s:return Trueelse:return False
print(search(t,s))

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com