随笔分类 - python
摘要:demo1 实现一个按优先级排序的队列, 并且在这个队列上面每次 pop 操作总是返回优先级最高的那个元素 输出: 使用: 仔细观察可以发现,第一个 pop() 操作返回优先级最高的元素。 另外注意到如果两个有着相同优先级的元素( foo 和 grok ),pop 操作按照它们被插入到队列的顺序返回
阅读全文
摘要:Given an array of integers, every element appears # twice except for one. Find that single one. 输出:
阅读全文
摘要:demo1 输出: demo2 输出: demo3 堆数据结构最重要的特征是 heap[0] 永远是最小的元素。并且剩余的元素可以很容易的通过调用 heapq.heappop() 方法得到, 该方法会先将第一个元素弹出来,然后用下一个最小的元素来取代被弹出元素(这种操作时间复杂度仅仅是 O(log
阅读全文
摘要:你构建了一个自定义容器对象,里面包含有列表、元组或其他可迭代对象。 你想直接在你的这个新容器对象上执行迭代操作。 输出: 讨论 Python的迭代器协议需要 __iter__() 方法返回一个实现了 __next__() 方法的迭代器对象。 如果你只是迭代遍历其他容器的内容,你无须担心底层是怎样实现
阅读全文
摘要:or 下面的交互示例向我们演示了迭代期间所发生的基本细节:
阅读全文
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word
阅读全文
摘要:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. 输出:
阅读全文
摘要:Given a collection of distinct integers, return all possible permutations.
阅读全文
摘要:class Solution(object): def divide(self, dividend, divisor): """ :type dividend: int :type divisor: int :rtype: int """ ispositive = True ...
阅读全文
摘要:可以看到每一个发布都需要大约3s,所以在发布前要等待3s以上。 发布 订阅:
阅读全文
摘要:print()函数,我们可以看出,在Python IDLE中直接输入的字符串都是有类型的,而print打印后的字符串相当于一串文字,把字符串的引号也省略了,没有类型 print()函数,生成可读性更好的输出, 它会省去引号并打印 str()函数,用于将值转化为适于人阅读的字符串的形式 repr()函
阅读全文
摘要:abs(number) ,返回数字的绝对值cmath.sqrt(number) ,返回平方根,也可以应用于负数float(object) ,把字符串和数字转换为浮点数help() ,提供交互式帮助input(prompt) ,获取用户输入int(object) ,把字符串和数字转换为整数math.c
阅读全文
摘要:#coding=utf-8 import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget, QApplication from PyQt5.QtGui import QPixmap, QPainter, QBitmap, QCursor import PyQt5.QtCore as QtCore cl...
阅读全文
摘要:有多种安装Python-Client的方法: 第一种 第二种 第三种 这里我们使用pip
阅读全文
摘要:# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def removeNthFromEnd(self,...
阅读全文
摘要:class Solution(object): def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """ l = len...
阅读全文
摘要:class Solution(object): def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ if digits == "": return []...
阅读全文
摘要:client: server: 参考: https://www.cnblogs.com/suguangti/p/10814737.html https://www.cnblogs.com/huihui0708/p/8594817.html
阅读全文

浙公网安备 33010602011771号