![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
王二小、
这个作者很懒,什么都没留下…
展开
-
python-Counter计数函数以及most_common函数
>>> c = Counter() # 创建一个新的空counter>>> c = Counter('abcasdf') # 一个迭代对象生成的counter>>> c = Counter({'red': 4, 'yello': 2}) # 一个映射生成的counter>>> c = Counter(cats=2, dogs=5)原创 2022-04-24 15:44:58 · 1538 阅读 · 0 评论 -
leetcode——5. 最长回文子串
class Solution: def longestPalindrome(self, s: str) -> str: max_len = 1 # 从第二个字符开始判断 d = {} if len(s) == 1: return s mark = 0 for i in range(1, len(s)): if i - max_len >=0 an原创 2021-07-28 16:51:19 · 93 阅读 · 0 评论 -
leetcode——4. 寻找两个正序数组的中位数
class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: new_num = [] nums1.extend(nums2) print(nums1) print(1//2) nums1.sort() if len(nums1) % 2 == 0:原创 2021-07-26 19:45:43 · 68 阅读 · 0 评论 -
leetcode——3. 无重复字符的最长子串
class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if len(s) == 0: return 0 if len(s) > 0: d = {} count = 0 max_count = [0] new_start = 0原创 2021-07-26 16:25:09 · 67 阅读 · 0 评论 -
leetcode——2. 两数相加
# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: node = te原创 2021-07-26 16:16:49 · 64 阅读 · 0 评论 -
leetcode——1. 两数之和
class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: d = {} for i in range(len(nums)): if nums[i] in d: return [d[nums[i]], i] d[target - nums[i]] = i return原创 2021-07-26 16:15:58 · 57 阅读 · 0 评论 -
图片np.array格式转成bytes格式
图片np.array格式转成bytes格式需要将图片的np.array数据转换为bytes,转换之后的bytes数据要等价于open(file,“rb”)。在使用numpy的tobytes(等价于tostring)方法发现得到的bytes数据并不等价于open(file,“rb”)数据,需要对array数据进行相同的图片格式编码之后,再使用tobytes才行。import cv2img_path = "img/test.jpg"# 打开图片文件获取二进制数据with open(img_path,原创 2020-12-15 09:37:36 · 2493 阅读 · 5 评论 -
Python中的itertools.permutations
返回可迭代对象的所有全排列方式import itertoolssum2 = 0a = [1,2,3]for i in itertools.permutations(a, 2): print("%d%d"%(i[0],i[1])) sum2 += 1print(sum2)1213212331326sum2 = 0for i in itertools.perm...原创 2020-01-13 17:01:33 · 1204 阅读 · 0 评论 -
剑指offer —— 从尾到头打印链表 python
# -*- coding:utf-8 -*-class ListNode: def __init__(self, x): self.val = x self.next = Noneclass Solution: # 返回从尾部到头部的?????列表值序列,例如[1,2,3] def printListFromTailToHead(self...原创 2019-09-29 17:51:41 · 98 阅读 · 0 评论 -
剑指offer ——替换空格python
# -*- coding:utf-8 -*-class Solution: # s 源字符串 def replaceSpace(self, s): if type(s) != str: return return s.replace(' ','%20')原创 2019-09-28 02:14:39 · 76 阅读 · 0 评论 -
剑指offer ——二维数组中的查找python
# -*- coding:utf-8 -*-class Solution: # array 二维列表 def Find(self, target, array): if array==[[]]: return False row=len(array) col=len(array[0]) i=0...原创 2019-09-28 01:59:47 · 107 阅读 · 0 评论