python1-字符最长公共前缀

# 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"]))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码字神经元

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值