58 Length of Last Word 简单题
python:
class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
if s.strip()=="": return 0;
return len(s.strip().split()[-1])
java:
public class Solution {
public int lengthOfLastWord(String s) {
return s.trim().length() - s.trim().lastIndexOf(" ") -1 ;
}
}
- Find Duplicate File in System python
class Solution(object):
def findDuplicate(self, paths):
"""
:type paths: List[str]
:rtype: List[List[str]]
"""
res = {}
ans = []
for path in paths:
files = path.split()
dic = files[0]
for file in files[1:]:
file_content = file.split("(")
filename = file_content[0]
content = file_content[-1][:-1]
print filename
print content
if content in res:
res[content].append(dic+"/"+filename)
else:
res[content] = []
res[content].append(dic+"/"+filename)
for re in res:
if len(res[re])>=2:
ans.append(res[re])
return ans
221

被折叠的 条评论
为什么被折叠?



