假设我们有一个小写字母字符串s,我们必须找到一个字符串,其中s的所有元音都按排序顺序排列,随后是s的所有辅音。
因此,如果输入像“ helloworld”,则输出将为“ eoodhlllrw”,因为元音为“ eo”,辅音的排序顺序为“ dhlllrw”
为了解决这个问题,我们将遵循以下步骤-
k:=空字符串,t:=空字符串
对于s中的每个字符c,
t:= t连接c
k:= k连接c
如果c是元音,则
除此以外,
返回(排序后为k,排序后为串联)
让我们看下面的实现以更好地理解-
class Solution:
def solve(self, s):
vowels = 'aeiou' k = ''
t = ''
for c in s:
if c in vowels :
k = k + c
else :
t = t + c
k = ''.join(sorted(k))
t = ''.join(sorted(t))
return k + t
ob = Solution() print(ob.solve("helloworld"))"helloworld"
输出结果
eoodhlllrw