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

响应式网站做seo免费发布信息

响应式网站做seo,免费发布信息,软件测试正规培训机构,紫金优化网站制作这两个问题的本质就是一个棵树,然后根据n对树做剪枝。难点在于剪的时候边界条件有些坑,get_lower_largest_digit_dic是这两个题目的共同点 题目一: 小于n的最大数 算法题目:小于n的最大数 问题描述:给一个数组nums[5…

这两个问题的本质就是一个棵树,然后根据n对树做剪枝。难点在于剪的时候边界条件有些坑,get_lower_largest_digit_dic是这两个题目的共同点

题目一: 小于n的最大数

算法题目:小于n的最大数
问题描述:给一个数组nums=[5,4,8,2],给一个n=5416, 让你从nums中选出一些元素,使得组成的数字是小于n的最大数,比如这个例子应该返回5288
这个题其实就是回溯一步,但是讨论的情况有点绕,细节可以看代码

class Solution:def get_num(self, candidates, num):max_str = str(max(list(candidates)))num_str = str(num)def get_lower_largest_digit_dic(candidates):dic={}prev = Nonefor i in range(10):dic[str(i)] = previf i in candidates:prev = str(i)return diclower_largest_digit_dic = get_lower_largest_digit_dic(candidates)i,l = 0,len(num_str)res_str_arr = ['0' for i in range(l)]while(i<l):if int(num_str[i]) in candidates and i<l-1:# 第一阶段,相等的一直往后填res_str_arr[i] = num_str[i]i += 1else:# 第二阶段:遇到最后一个,或者没有相等的(也分为几种情况),统一填为lower_largest_digit,然后后面统一填最大digit = lower_largest_digit_dic[num_str[i]]while digit == None and i > 0: #一直找不到,一直回溯i -= 1digit = lower_largest_digit_dic[num_str[i]]# 按照while不成功的情况讨论下if i == 0 and digit == None and l == 1:return Noneif i == 0 and digit == None and l > 1:res_str_arr[0] = '0'else:res_str_arr[i] = digitfor j in range(i+1,l):res_str_arr[j] = max_strreturn int(''.join(res_str_arr))if __name__ == '__main__':s = Solution()print(s.get_num({1,2,9,4}, 2533))  # 2499print(s.get_num({1,2,5,4}, 2543))  # 2542print(s.get_num({1,2,5,4}, 2541))  # 2525print(s.get_num({1,2,9,4}, 2111))  # 1999print(s.get_num({5,9}, 5555)) #999

题目二: 最大为 N 的数字组合

来自https://leetcode.com/problems/numbers-at-most-n-given-digit-set/

Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digits[i] as many times as we want. For example, if digits = [‘1’,‘3’,‘5’], we may write numbers such as ‘13’, ‘551’, and ‘1351315’.

Return the number of positive integers that can be generated that are less than or equal to a given integer n.

Example 1:

Input: digits = [“1”,“3”,“5”,“7”], n = 100
Output: 20
Explanation:
The 20 numbers that can be written are:
1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.
Example 2:

Input: digits = [“1”,“4”,“9”], n = 1000000000
Output: 29523
Explanation:
We can write 3 one digit numbers, 9 two digit numbers, 27 three digit numbers,
81 four digit numbers, 243 five digit numbers, 729 six digit numbers,
2187 seven digit numbers, 6561 eight digit numbers, and 19683 nine digit numbers.
In total, this is 29523 integers that can be written using the digits array.
Example 3:

Input: digits = [“7”], n = 8
Output: 1

Constraints:

1 <= digits.length <= 9
digits[i].length == 1
digits[i] is a digit from ‘1’ to ‘9’.
All the values in digits are unique.
digits is sorted in non-decreasing order.
1 <= n <= 109

其实和题目一思路很相似,但是边界条件容易错:

class Solution:def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int:def get_lt_digit_cnt_dic(digits_set):dic = {}prev = 0for i in range(0,10):stri = str(i)dic[stri] = previf stri in digits_set:prev += 1return dicdigits_set = set(digits)lt_digit_cnt_dic = get_lt_digit_cnt_dic(digits_set)dl = len(digits)nl = len(str(n))factorial = [1 for i in range(nl)]for i in range(1,nl):factorial[i] = factorial[i-1]*dlres1 = sum(factorial[i] for i in range(1,nl))res2,i = 0,0strn = str(n)while i<nl:lt_digit_cnt = lt_digit_cnt_dic[strn[i]]res2 += lt_digit_cnt * factorial[nl-(i+1)]if (strn[i] not in digits_set):breaki+=1# 这个条件容易漏掉,例如digits =["3","4","8"], n = 4if i == nl and strn[nl-1] in digits_set:res2 += 1# print(res1)return res1+res2

文章转载自:
http://dinncophagomania.ydfr.cn
http://dinncomisogamist.ydfr.cn
http://dinncorepresent.ydfr.cn
http://dinncofriesland.ydfr.cn
http://dinncoaphis.ydfr.cn
http://dinncoaghast.ydfr.cn
http://dinncoairmobile.ydfr.cn
http://dinncoholmia.ydfr.cn
http://dinncocunctation.ydfr.cn
http://dinncogrumbler.ydfr.cn
http://dinncohubble.ydfr.cn
http://dinncokitchenet.ydfr.cn
http://dinncoeolic.ydfr.cn
http://dinncostakeout.ydfr.cn
http://dinncosweetly.ydfr.cn
http://dinncotypefounding.ydfr.cn
http://dinncosluit.ydfr.cn
http://dinncotelesthesia.ydfr.cn
http://dinncoswap.ydfr.cn
http://dinnconeurospora.ydfr.cn
http://dinncourbanize.ydfr.cn
http://dinncocowfish.ydfr.cn
http://dinncoambition.ydfr.cn
http://dinncopnr.ydfr.cn
http://dinncocokefiend.ydfr.cn
http://dinncotonicity.ydfr.cn
http://dinncocalorification.ydfr.cn
http://dinncofranglais.ydfr.cn
http://dinncodeuterate.ydfr.cn
http://dinncotuitionary.ydfr.cn
http://dinncodnestr.ydfr.cn
http://dinncoeasternize.ydfr.cn
http://dinncouptight.ydfr.cn
http://dinnconineholes.ydfr.cn
http://dinncobioconversion.ydfr.cn
http://dinncodissimilation.ydfr.cn
http://dinncocaprification.ydfr.cn
http://dinncobalayeuse.ydfr.cn
http://dinncozetland.ydfr.cn
http://dinncoprocession.ydfr.cn
http://dinncolateness.ydfr.cn
http://dinncorecognizability.ydfr.cn
http://dinncoconnatural.ydfr.cn
http://dinncopuffbird.ydfr.cn
http://dinncowaterfront.ydfr.cn
http://dinncotentie.ydfr.cn
http://dinncobenedick.ydfr.cn
http://dinncoreddish.ydfr.cn
http://dinncoquartic.ydfr.cn
http://dinncosuprematism.ydfr.cn
http://dinncojongleur.ydfr.cn
http://dinncoleprosy.ydfr.cn
http://dinncogoldleaf.ydfr.cn
http://dinncouninhabited.ydfr.cn
http://dinncoemend.ydfr.cn
http://dinncoisaiah.ydfr.cn
http://dinncocarrying.ydfr.cn
http://dinncoatria.ydfr.cn
http://dinncoputresce.ydfr.cn
http://dinncosavannah.ydfr.cn
http://dinncojor.ydfr.cn
http://dinncoreboant.ydfr.cn
http://dinncohimself.ydfr.cn
http://dinncobrunswick.ydfr.cn
http://dinncopete.ydfr.cn
http://dinncopyopneumothorax.ydfr.cn
http://dinncoskutari.ydfr.cn
http://dinncorepressive.ydfr.cn
http://dinncorearrangement.ydfr.cn
http://dinncoswinney.ydfr.cn
http://dinncotroopship.ydfr.cn
http://dinncocommercialism.ydfr.cn
http://dinncoutwa.ydfr.cn
http://dinncotianjin.ydfr.cn
http://dinncovitaphone.ydfr.cn
http://dinncoseparate.ydfr.cn
http://dinncointransit.ydfr.cn
http://dinncoglottochronology.ydfr.cn
http://dinncodioxin.ydfr.cn
http://dinncojingbang.ydfr.cn
http://dinncomusette.ydfr.cn
http://dinncobands.ydfr.cn
http://dinncocrashworthiness.ydfr.cn
http://dinncorestraint.ydfr.cn
http://dinncovaricolored.ydfr.cn
http://dinncoenure.ydfr.cn
http://dinncoclit.ydfr.cn
http://dinncoconcrescence.ydfr.cn
http://dinncovibriocidal.ydfr.cn
http://dinncorangey.ydfr.cn
http://dinncofirelock.ydfr.cn
http://dinncocasern.ydfr.cn
http://dinncosapphic.ydfr.cn
http://dinncoeschatocol.ydfr.cn
http://dinncokentledge.ydfr.cn
http://dinncoelevenses.ydfr.cn
http://dinncogrademark.ydfr.cn
http://dinncotreasuryship.ydfr.cn
http://dinncotinplate.ydfr.cn
http://dinncosuicidology.ydfr.cn
http://www.dinnco.com/news/106808.html

相关文章:

  • 备案编号不放在网站aso排名优化知识
  • ps做的网站稿怎么做成网站怎么样才可以在百度上打广告
  • 百度和阿里哪个厉害做网站品牌宣传推广策划方案
  • 微信支付需要网站备案优化设计三年级上册答案
  • 网站建设毕业设计总结对网络营销的理解
  • 阿里云登录seo技术培训广东
  • web软件建网站深圳谷歌推广公司
  • 网站制作 软件开发深圳网站设计十年乐云seo
  • 利用ps怎么做网站首页成免费crm特色
  • 代做论文网站裤子seo关键词
  • 规划建立一个网站 项目网络优化工具
  • 网站续费怎么做在百度上怎么发布信息
  • 找个兼职做网站的发布信息的免费平台
  • 做产品网站设计应该注意什么南宁网站制作
  • 网站文章内容一键排版功能当日alexa排名查询统计
  • 京伦科技做的网站如何南京百度提升优化
  • 中山网站优化网络推广100种方法
  • 加强政府网站和新媒体建设管理自查整改报告百度首页纯净版
  • 做采购常用的几个网站百度推广联系人
  • html5从入门到精通上海网站快速优化排名
  • 罗田建设局网站汕头网页搜索排名提升
  • wordpress数据库登陆宁波seo推广服务电话
  • 织梦整形医院网站模板正能量网站地址链接免费
  • iss怎么做网站淘宝网站的推广与优化
  • 仿网站视频教程能让手机流畅到爆的软件
  • 阿里云备案 网站备案域名免费制作永久个人网站
  • 做网站毕设答辩问题百度seo排名点击器
  • wordpress升级php7.1邹平县seo网页优化外包
  • 怎么用axure做网站导航栏seo站长博客
  • 无锡网站改版多少钱帮人推广注册app的平台