# class solution(object):
# def constructRectangle(self,area):
# import math
# w,i=1,0
# lengh=int(math.sqrt(area))
# for w_i in range (1,lengh+1):
# if area%w_i==0:
# width=max(w_i,i)
# val=width
# return [int(area/width),width]
#
# if __name__ == '__main__':
# a = solution()
# b = a.constructRectangle(10)
# print(b)
# import math
# class Solution(object):
# def constructRectangle(self, area):
# """
# :type area: int
# :rtype: List[int]
# """
# W = int(math.sqrt(area))
# while area%W != 0:
# W -= 1
# return [int(area/W),W]
#
#
# if __name__ == '__main__':
# a = Solution()
# b=a.constructRectangle(100)
#
# print(b)
# class Solution():
# def longestCommonPrefix(self,strs):
# b=""
# if len(strs)==0:
# return ""
# for i in zip(*strs):
# if len(set(i))==1:
# b+=i[0]
# else:
# return b
# return b
#
# if __name__ == '__main__':
# a = Solution()
# c = a.longestCommonPrefix(["aebr","aewr","aedmh"]) # z注意:是列表
# print(c)
# class Solution(object):
# def longestCommonPrefix(self, strs):
# """
# :type strs: List[str]
# :rtype: str
# """
# # 判断是否为空
# if not strs:
# return ''
# # 在使用max和min的时候已经把字符串比较了一遍
# # 当前列表的字符串中,每个字符串从第一个字母往后比较直至出现ASCII码 最小的字符串
# s1 = min(strs)
# print(s1)
# # 当前列表的字符串中,每个字符串从第一个字母往后比较直至出现ASCII码 最大的字符串
# s2 = max(strs)
# print(s2)
# # 使用枚举变量s1字符串的每个字母和下标
# for i, c in enumerate(s1):
# print([i,c])
# # 比较是否相同的字符串,不相同则使用下标截取字符串
# if c != s2[i]:
# return s1[:i]
# return s1
#
#
# if __name__ == '__main__':
# s = Solution()
# print(s.longestCommonPrefix(["flower", "foow", "foight","flwewe"]))
python1-字符最长公共前缀
于 2022-03-02 21:31:37 首次发布