1,字符串的旋转
def ReverseString(s,fr,to):
s = list(s)
while (fr < to):
t=s[fr]
s[fr]=s[to]
s[to] = t
fr += 1
to -= 1
return "".join(s)
def leftRotateString(s,m):
le=ReverseString(s,0,m-1)
mi=ReverseString(s,m,len(s)-1)
re=ReverseString(s,0,len(s)-1)
return re
b = leftRotateString('abcdef',3)
2,单词旋转
def reverseWord(s):
result=[]
result=s.split(" ")
return " ".join(result[::-1])
#print(reverseWord("I am a student."))
3,字符串的包含
def StringContain(a,b):
l=list(a)
l.sort()
print(l)
print(list(b).sort())
for c in b:
if a.find(c)==-1:
print(c)
return False
return True
print(StringContain("ABCFEGD","ABCA"))
4,变位词(兄弟字符串)
def isPairstring(a,b):
a=list(a)
b=list(b)
a.sort()
b.sort()
a="".join(a)
b="".join(b)
if (a in b) and (b in a):
return True
else:
return False
#print(isPairstring("badd","adbde"))