大家好,我是毛毛。ヾ(´∀ ˋ)ノ
废话不多说开始今天的解题Day~
Given two strings s
and goal
, return true
if and only if s
can become goal
after some number of shifts on s
.
A shift on s
consists of moving the leftmost character of s
to the rightmost position.
s = "abcde"
, then it will be "bcdea"
after one shift.Input: s = "abcde", goal = "cdeab"
Output: true
Input: s = "abcde", goal = "abced"
Output: false
1 <= s.length, goal.length <= 100
s
and goal
consist of lowercase English letters.首先先简单的翻译一下题目
给一个字串s
跟目标字串goal
,要判断goal
是不是可以透过位移s
的字串来得到。
作法大致上是这样
s[index:]
可以得到从index
这个位置到s
最後的所有字元,s[index]
可以在得到从s
的头到index前的所有字元,把两个加起来,就可以达到shift的效果。class Solution:
def rotateString(self, s: str, goal: str) -> bool:
for index in range(len(s)):
if (s[index:] + s[:index]) == goal:
return True
return False
大家明天见
>>: [Day - 28] - 运用Spring MockMvc 迈向自动化测试之路
前言 我们花了将近一周的时间来介绍部署深度学习模型背後的概念,我想大家应该很想知道究竟该怎麽实作,所...
管理讯息的功能有 新增团购讯息 删除团购讯息 查询团购讯息 手动新增团购者 手动删除团购者 新增团购...
今天继续来谈论静态爬虫,昨天都在讲解文字,今天来讲讲图片的部分。常常看到一个网页中有很多漂亮的图片,...
新手任务 ...
在 App 需求中 若页面需要通过 URL 渲染远端 HTML 页面 若页面资料提供的是 html...