Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfcd1f83

Browse files
T面试题
1 parent18d3ad9 commitfcd1f83

File tree

3 files changed

+118
-54
lines changed

3 files changed

+118
-54
lines changed

‎.idea/workspace.xml

Lines changed: 63 additions & 54 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
面试题:
3+
一个句子的所有单词的首字母大写,其余小写
4+
'''
5+
deftitle(s):
6+
ifnots:
7+
return""
8+
res=""
9+
diff=ord("a")-ord("A")
10+
foriinrange(1,len(s)):
11+
ifs[i-1]==" "ands[i]<="z"ands[i]>="a":
12+
res+=chr(ord(s[i])-diff)
13+
elifs[i-1]!=" "ands[i]<="Z"ands[i]>="A":
14+
res+=chr(ord(s[i])+diff)
15+
else:
16+
res+=s[i]
17+
ifs[0]<="z"ands[0]>="a":
18+
res=chr(ord(s[0])-diff)+res
19+
else:
20+
res=s[0]+res
21+
returnres
22+
23+
deftitle2(s):
24+
returns.title()
25+
26+
print(title2(" sDsa sddr jki "))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
求一个字符串的最长子串,其中子串所有字符相同
3+
面试题
4+
'''
5+
deffindCommonLCS(s):
6+
ifnots:
7+
return""
8+
iflen(s)==1:
9+
returns
10+
length=len(s)
11+
maxIndex,maxLength=0,1
12+
curIndex=0
13+
whilecurIndex<length:
14+
tempLength=1
15+
whilecurIndex+tempLength<lengthands[curIndex]==s[curIndex+tempLength]:
16+
tempLength+=1
17+
ifmaxLength<tempLength:
18+
maxLength=tempLength
19+
maxIndex=curIndex
20+
ifcurIndex+tempLength==length:
21+
break
22+
curIndex+=tempLength
23+
ifmaxLength==1:
24+
returns[0]
25+
else:
26+
res=s[maxIndex:maxIndex+maxLength]
27+
returnres
28+
29+
print(findCommonLCS("abbbasagsagsgdsaagaaccagcfsccccc"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp