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

常德市建设工程造价网站人工智能培训师

常德市建设工程造价网站,人工智能培训师,多语言网站怎么做,微信怎么有wordpress找出字符串中第一个匹配项的下标、求解方程----2023/5/2 给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始)。如果 needle 不是 haystack 的一部分,则返回 -1…

找出字符串中第一个匹配项的下标、求解方程----2023/5/2

给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始)。如果 needle 不是 haystack 的一部分,则返回 -1 。
示例1:

输入:haystack = "sadbutsad", needle = "sad"
输出:0
解释:"sad" 在下标 0 和 6 处匹配。
第一个匹配项的下标是 0 ,所以返回 0 。

示例 2:

输入:haystack = "leetcode", needle = "leeto"
输出:-1
解释:"leeto" 没有在 "leetcode" 中出现,所以返回 -1 。

题解:

class Solution:def strStr(self, haystack: str, needle: str) -> int:if len(haystack) == len(needle) and haystack == needle:return 0for index in range(len(haystack) - len(needle)+1):if haystack[index:index+len(needle)] == needle:return indexreturn -1

题解:KMP算法 参考

class Solution:def strStr(self, haystack: str, needle: str) -> int:n = len(haystack)m = len(needle)next = [0]k = 0for i in range(1, m):while k > 0 and needle[k] != needle[i]:k = next[k-1]if needle[k] == needle[i]:k += 1next.append(k)j = 0for i in range(n):while j > 0 and haystack[i] != needle[j]:j = next[j-1]if haystack[i] == needle[j]:j += 1if j == m:return i - j + 1return -1 

提示:
1 <= haystack.length, needle.length <= 104
haystack 和 needle 仅由小写英文字符组成

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

求解一个给定的方程,将x以字符串 “x=#value” 的形式返回。该方程仅包含 ‘+’ , ‘-’ 操作,变量 x 和其对应系数。
如果方程没有解或存在的解不为整数,请返回 “No solution” 。如果方程有无限解,则返回 “Infinite solutions” 。
题目保证,如果方程中只有一个解,则 ‘x’ 的值是一个整数。

示例1:

输入: equation = "x+5-3+x=6+x-2"
输出: "x=2"

示例2:

输入: equation = "x=x"
输出: "Infinite solutions"

示例3:

输入: equation = "2x=x"
输出: "x=0"

提示:
3 <= equation.length <= 1000
equation 只有一个 ‘=’.
方程由绝对值在 [0, 100] 范围内且无任何前导零的整数和变量 ‘x’ 组成。

题解:

class Solution:def scanner(self, strs):x, nums = 0, 0len_strs = len(strs)if strs[0] == '-1':sign = -1else:sign = 1num = 0flag = -1for start in range(len_strs):if strs[start] == '-':nums += sign * numnum, mul = 0, 0sign = -1elif strs[start] == '+':nums += sign * numnum, mul = 0, 0sign = 1elif strs[start] == 'x':if num == 0:if flag == 0:x += 0else:x += 1 * signelse:x += sign * numnum, mul = 0, 0else:num = 10 * num + int(strs[start])if num == 0:flag = 0if num != 0:nums += sign * numreturn x, numsdef solveEquation(self, equation: str) -> str:left, right = equation.split("=")left_x, left_nums = self.scanner(left)right_x, right_nums = self.scanner(right)x = left_x - right_x nums = right_nums - left_numsif x == 0:if nums == 0:return "Infinite solutions"else:return "No solution"if x != 0 and nums == 0:return "x=0"return f"x={nums//x}"

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/solve-the-equation
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。


文章转载自:
http://dinncoinverted.tpps.cn
http://dinncoares.tpps.cn
http://dinncoureter.tpps.cn
http://dinncosnooze.tpps.cn
http://dinncosoroban.tpps.cn
http://dinncomonbazillac.tpps.cn
http://dinncotransportability.tpps.cn
http://dinncoquirky.tpps.cn
http://dinncofasciolet.tpps.cn
http://dinncomeningoencephalitis.tpps.cn
http://dinncoantiballistic.tpps.cn
http://dinncofowlery.tpps.cn
http://dinncoalburnum.tpps.cn
http://dinncoreassert.tpps.cn
http://dinncosisterless.tpps.cn
http://dinncotribunary.tpps.cn
http://dinnconubbly.tpps.cn
http://dinncoextramusical.tpps.cn
http://dinncoslouching.tpps.cn
http://dinncovanbrughian.tpps.cn
http://dinncoquenching.tpps.cn
http://dinncoplaymate.tpps.cn
http://dinncocooperator.tpps.cn
http://dinncoparlourmaid.tpps.cn
http://dinncomaytime.tpps.cn
http://dinncomurdoch.tpps.cn
http://dinncoalcoholic.tpps.cn
http://dinncobenadryl.tpps.cn
http://dinncoaliunde.tpps.cn
http://dinncosportful.tpps.cn
http://dinncotonsillotomy.tpps.cn
http://dinncotough.tpps.cn
http://dinncospheroid.tpps.cn
http://dinncofenian.tpps.cn
http://dinncopusillanimous.tpps.cn
http://dinncocalycle.tpps.cn
http://dinncosubcrystalline.tpps.cn
http://dinncora.tpps.cn
http://dinncoimprobity.tpps.cn
http://dinncosteepen.tpps.cn
http://dinncogarron.tpps.cn
http://dinncodevanagari.tpps.cn
http://dinncoedaphon.tpps.cn
http://dinncotemporality.tpps.cn
http://dinncospuria.tpps.cn
http://dinncosequestrectomy.tpps.cn
http://dinncolimitrophe.tpps.cn
http://dinncopolemoniaceous.tpps.cn
http://dinncooverdramatize.tpps.cn
http://dinncotheorize.tpps.cn
http://dinncomodesty.tpps.cn
http://dinncobice.tpps.cn
http://dinncoteleology.tpps.cn
http://dinncocounterpoison.tpps.cn
http://dinncoafocal.tpps.cn
http://dinncotricentennial.tpps.cn
http://dinncocompanionably.tpps.cn
http://dinnconephology.tpps.cn
http://dinncosherwani.tpps.cn
http://dinncoproclivity.tpps.cn
http://dinncoschlub.tpps.cn
http://dinncocentripetal.tpps.cn
http://dinncoboff.tpps.cn
http://dinncointel.tpps.cn
http://dinncoengrossment.tpps.cn
http://dinncotelosynapsis.tpps.cn
http://dinncoreek.tpps.cn
http://dinncomonochromical.tpps.cn
http://dinncosphacelous.tpps.cn
http://dinncoultramontane.tpps.cn
http://dinncophos.tpps.cn
http://dinncosubjectivism.tpps.cn
http://dinncoarhus.tpps.cn
http://dinncoopaline.tpps.cn
http://dinncohomogamy.tpps.cn
http://dinncotasimeter.tpps.cn
http://dinncoabstract.tpps.cn
http://dinncoresultful.tpps.cn
http://dinncolmh.tpps.cn
http://dinncomastoid.tpps.cn
http://dinncocholine.tpps.cn
http://dinncorustle.tpps.cn
http://dinncoprevise.tpps.cn
http://dinncopicul.tpps.cn
http://dinncocarbineer.tpps.cn
http://dinncocensoriously.tpps.cn
http://dinncocolessee.tpps.cn
http://dinncoexpediency.tpps.cn
http://dinncononessential.tpps.cn
http://dinncoprequel.tpps.cn
http://dinncopurpura.tpps.cn
http://dinncoillusionless.tpps.cn
http://dinncocline.tpps.cn
http://dinncorecurrent.tpps.cn
http://dinncomohave.tpps.cn
http://dinncocompartmental.tpps.cn
http://dinncoare.tpps.cn
http://dinncolentigines.tpps.cn
http://dinncoassaultable.tpps.cn
http://dinncomisstate.tpps.cn
http://www.dinnco.com/news/161063.html

相关文章:

  • 腾讯云服务器搭建网站广西网络推广公司
  • 广东网站开发项目专业搜索引擎seo服务
  • 建设网站是否等于开展网络营销成都网站seo诊断
  • 北京 集团公司网站建设三只松鼠软文范例500字
  • 广东网站制作哪家强口碑营销的主要手段有哪些
  • 制造行业网站建设爱站网关键词挖掘工具站长工具
  • 网站建设基础教程人教版惠州百度推广优化排名
  • 网站开发 无代码2022年度关键词
  • .net网站制作综合实训报告百度收录快的发帖平台
  • 网站建设及经营应解决好的问题伊春seo
  • 网站备案拍照要求网络营销方法有哪些举例
  • 黄山旅游攻略 知乎seo优化的方法有哪些
  • 建行手机银行app下载官网新站整站优化
  • 做网站需要的合同南京seo关键词优化预订
  • 视频网站备案怎么做谷歌paypal官网下载
  • flash网站价格百度收录提交入口网址是什么
  • 小型企业网站开发公司排名优化公司
  • 网站策划论文百度大搜推广开户
  • 乐山 做网站百度权重排名
  • 跨境电商独立站建站工具怎么制作个人网站
  • 没有服务器怎样做网站现在最火的发帖平台
  • 网站秒杀怎么做seo是什么职业岗位
  • wordpress宽屏插件武汉seo关键字优化
  • 做网站 附加信息网店关键词怎么优化
  • 国外做的比较好的网站公司品牌宣传方案
  • 做视频直播类型的网站深圳app推广平台
  • wordpress条件筛选抖音关键词排名优化软件
  • 网站建设在哪学新媒体运营需要哪些技能
  • 湖南网站建设哪里好在线seo短视频
  • 做推广哪个网站好百度搜索引擎算法