We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 18d3ad9 commit fcd1f83Copy full SHA for fcd1f83
3 files changed
.idea/workspace.xml
Target Offer/句子中单词首字母大写.py
@@ -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
20
+ res = s[0] + res
21
+ return res
22
+
23
+def title2(s):
24
+ return s.title()
25
26
+print(title2(" sDsa sddr jki "))
Target Offer/字符串具有相同字符的最长子串.py
@@ -0,0 +1,29 @@
+求一个字符串的最长子串,其中子串所有字符相同
+面试题
+def findCommonLCS(s):
+ if len(s) == 1:
+ return s
+ length = len(s)
+ maxIndex, maxLength = 0, 1
+ curIndex = 0
+ while curIndex < length:
+ tempLength = 1
+ while curIndex + tempLength < length and s[curIndex] == s[curIndex+tempLength]:
+ tempLength += 1
+ if maxLength < tempLength:
+ maxLength = tempLength
+ maxIndex = curIndex
+ if curIndex + tempLength == length:
+ break
+ curIndex += tempLength
+ if maxLength == 1:
+ return s[0]
+ res = s[maxIndex:maxIndex+maxLength]
27
28
29
+print(findCommonLCS("abbbasagsagsgdsaagaaccagcfsccccc"))
0 commit comments