Skip to content

Commit fcd1f83

Browse files
T面试题
1 parent 18d3ad9 commit fcd1f83

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 about customizing 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+
def title(s):
6+
if not s:
7+
return ""
8+
res = ""
9+
diff = ord("a") - ord("A")
10+
for i in range(1, len(s)):
11+
if s[i-1] == " " and s[i] <= "z" and s[i] >= "a":
12+
res += chr(ord(s[i]) - diff)
13+
elif s[i-1] != " " and s[i] <= "Z" and s[i] >= "A":
14+
res += chr(ord(s[i]) + diff)
15+
else:
16+
res += s[i]
17+
if s[0] <= "z" and s[0] >= "a":
18+
res = chr(ord(s[0]) - diff) + res
19+
else:
20+
res = s[0] + res
21+
return res
22+
23+
def title2(s):
24+
return s.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+
def findCommonLCS(s):
6+
if not s:
7+
return ""
8+
if len(s) == 1:
9+
return s
10+
length = len(s)
11+
maxIndex, maxLength = 0, 1
12+
curIndex = 0
13+
while curIndex < length:
14+
tempLength = 1
15+
while curIndex + tempLength < length and s[curIndex] == s[curIndex+tempLength]:
16+
tempLength += 1
17+
if maxLength < tempLength:
18+
maxLength = tempLength
19+
maxIndex = curIndex
20+
if curIndex + tempLength == length:
21+
break
22+
curIndex += tempLength
23+
if maxLength == 1:
24+
return s[0]
25+
else:
26+
res = s[maxIndex:maxIndex+maxLength]
27+
return res
28+
29+
print(findCommonLCS("abbbasagsagsgdsaagaaccagcfsccccc"))

0 commit comments

Comments
 (0)