当前位置: 首页 > wzjs >正文

制作网站购买主机自助建站seo

制作网站购买主机,自助建站seo,wordpress首页中不显示文章,备案期间怎么做网站记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步 目录 6/2 135. 分发糖果6/3 1298. 你能从盒子里获得的最大糖果数6/4 3403. 从盒子中找出字典序最大的字符串 I6/5 1061. 按字典序排列最小的等效字符串6/6 2434. 使用机器人打印…

记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步


目录

      • 6/2 135. 分发糖果
      • 6/3 1298. 你能从盒子里获得的最大糖果数
      • 6/4 3403. 从盒子中找出字典序最大的字符串 I
      • 6/5 1061. 按字典序排列最小的等效字符串
      • 6/6 2434. 使用机器人打印字典序最小的字符串
      • 6/7 3170. 删除星号以后字典序最小的字符串
      • 6/8


6/2 135. 分发糖果

初始化每人一个糖
从1开始遍历队列 与前一个位置比较如果 分数比前一个位置大 那么糖的数量为前一个位置+1
倒序队列和糖果list 再一次从1开始遍历队列 相当于倒的在比较一次
此时如果分数比前一个位置大 那么糖的数量为max(当前数量,前一个位置+1)
最后求糖果list的和

def candy(ratings):""":type ratings: List[int]:rtype: int"""l = len(ratings)if l==0:return 0candys =[1]*lfor i in range(1,l):if ratings[i]>ratings[i-1]:candys[i] = candys[i-1]+1candys.reverse()ratings.reverse()for i in range(1,l):if ratings[i]>ratings[i-1]:candys[i] = max(candys[i],candys[i-1]+1)return sum(candys)def candy2(ratings):""":type ratings: List[int]:rtype: int"""n = len(ratings)if n==0:return 0candy = [1]*nfor i in range(1,n):if ratings[i]>ratings[i-1]:candy[i] = candy[i-1]+1for i in range(n-1,0,-1):if ratings[i]<ratings[i-1]:candy[i-1] = max(candy[i-1],candy[i]+1)return sum(candy)

6/3 1298. 你能从盒子里获得的最大糖果数

def maxCandies(status, candies, keys, containedBoxes, initialBoxes):""":type status: List[int]:type candies: List[int]:type keys: List[List[int]]:type containedBoxes: List[List[int]]:type initialBoxes: List[int]:rtype: int"""import collectionsn=len(status)canopen = [status[i]==1 for i in range(n)]hasbox,used=[False]*n,[False]*nl=collections.deque()ans=0for box in initialBoxes:hasbox[box]=Trueif canopen[box]:l.append(box)used[box]=Trueans+=candies[box]while len(l)>0:cur = l.popleft()for k in keys[cur]:canopen[k]=Trueif not used[k] and hasbox[k]:l.append(k)used[k]=Trueans+=candies[k]for box in containedBoxes[cur]:hasbox[box]=Trueif not used[box] and canopen[box]:l.append(box)used[box]=Trueans+=candies[box]return ans

6/4 3403. 从盒子中找出字典序最大的字符串 I

find找到整个字符串中字典序最大的的字符串
根据朋友数量看是否需要去掉一部分尾部

def answerString(word, numFriends):""":type word: str:type numFriends: int:rtype: str"""def find(s):i,j=0,1n=len(s)while j<n:k=0while j+k<n and s[i+k]==s[j+k]:k+=1if j+k<n and s[i+k]<s[j+k]:i,j=j,max(j+1,i+k+1)else:j=j+k+1return s[i:]if numFriends==1:return wordsub=find(word)n=len(word)m=len(sub)return sub[:min(m,n-numFriends+1)]

6/5 1061. 按字典序排列最小的等效字符串

并查集

def smallestEquivalentString(s1, s2, baseStr):""":type s1: str:type s2: str:type baseStr: str:rtype: str"""class UnionFind:def __init__(self,n):self.l = list(range(n))def find(self,x):if self.l[x]!=x:self.l[x]=self.find(self.l[x])return self.l[x]def union(self,x,y):x=self.find(x)y=self.find(y)if x==y:returnif x>y:x,y=y,xself.l[y]=xuf=UnionFind(26)for x,y in zip(s1,s2):uf.union(ord(x)-ord('a'), ord(y)-ord('a'))return ''.join(chr(ord('a')+uf.find(ord(c)-ord('a'))) for c in baseStr)

6/6 2434. 使用机器人打印字典序最小的字符串

将s中的字符依次入栈
如果当前栈顶的字符小于等于 剩余字符中最小的
则可以出栈

def robotWithString(s):""":type s: str:rtype: str"""from collections import Counter cnt = Counter(s)st=[]ret=[]minc='a'for c in s:st.append(c)cnt[c]-=1while minc!='z' and cnt[minc]==0:minc = chr(ord(minc)+1)while st and st[-1]<=minc:ret.append(st.pop())return ''.join(ret)

6/7 3170. 删除星号以后字典序最小的字符串

用一个26位的list 记录每个字符的位置
遇到*时 从小到大找到最小字典序字符 去除最靠后位置的字符

def clearStars(s):""":type s: str:rtype: str"""l=list(s)cnt = [[] for _ in range(26)]for i,c in enumerate(s):if c!='*':cnt[ord(c)-ord('a')].append(i)else:for j in range(26):if cnt[j]:l[cnt[j].pop()]='*'breakreturn ''.join(c for c in l if c!='*')

6/8


http://www.dtcms.com/wzjs/263720.html

相关文章:

  • 镜像网站是怎么做的石家庄seo网站管理
  • 三门峡建设银行网站网络宣传渠道
  • 重庆品牌网站建设公司哪家好南宁seo产品优化服务
  • 杭州g20网站建设公司市场营销方案怎么写
  • php手机网站模板短期职业技能培训班
  • 知乎 做照片好的网站站长论坛
  • 建站公司用米拓模板我们公司被起诉了要怎么办武汉seo优化排名公司
  • 今日军事新闻最新消息新闻福州短视频seo机会
  • 做独立网站需要什么深圳关键词快速排名
  • 个门户网站需要留电话号码的广告
  • 陕西网站建设培训爱站网使用体验
  • onethink做移动网站免费优化网站
  • wordpress账号广州网站优化排名
  • 辽宁省人民政府公报广州seo招聘
  • 十堰为企业做网站的单位汕头seo代理商
  • wamp网站开发aso推广方案
  • 成都最近有疫情出现吗武汉seo网站排名
  • 网站优化的优势seo综合查询怎么用的
  • wordpress模板函数seo做什么网站赚钱
  • 解析网站微营销官网
  • 英德市建设及城乡管理局网站seo最强
  • 做网站 租服务器吗seo在线论坛
  • 国外的购物网站有哪些网店如何营销推广
  • 江苏建信建设集团网站韶关seo
  • 什么网站是教做纸工的视频推广一条多少钱
  • 做的网站提示不安全2022百度收录越来越难了
  • 公司做网站的费用怎么做账总裁班课程培训
  • 初学者学做网站怎么学林哥seo
  • 做动漫的游戏 迅雷下载网站广州最新消息
  • 哪个网站做图文素材多活动推广软文