摘要: 以下理解整理翻译自Stackoverflow-What are metaclasses in Python? 关于这个已经有博主翻译转载过了,深刻理解Python中的元类(metaclass) 1、Python中的类 在理解元类之前,你需要掌握Python中的类。Python中借用了SmallTal 阅读全文
posted @ 2019-02-13 11:55 adminyzz 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 1. CREATE DATABASE dbname; 2. DROP DATABASE dbname; 3. GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'usercode'; 4. USE dbn 阅读全文
posted @ 2018-11-09 10:54 adminyzz 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 257. Binary Tree Paths 深度优先遍历 1 class Solution: 2 def binaryTreePaths(self, root): 3 """ 4 :type root: TreeNode 5 :rtype: List[str] 6 """ 7 res, path_ 阅读全文
posted @ 2018-11-01 19:16 adminyzz 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 303. Range Sum Query - Immutable 使用类的方法,求下标i-j之和。 在初始化中处理数据可以节省大量时间。 1 class NumArray: 2 3 def __init__(self, nums): 4 """ 5 :type nums: List[int] 6 " 阅读全文
posted @ 2018-10-30 19:31 adminyzz 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 235. Lowest Common Ancestor of a Binary Search Tree 在一个二叉搜索树中找两个节点的最小公共父节点。 使用二叉搜索树的性质,设x是二叉搜索树中的一个结点。如果y是x左子树中的一个结点,那么会有y.key<=x.key;如果y是x右子树中的一个节点,那 阅读全文
posted @ 2018-10-29 18:20 adminyzz 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 225. Implement Stack using Queues 实现栈的操作方法。通过列表方法实现。 1 class MyStack(object): 2 3 def __init__(self): 4 """ 5 Initialize your data structure here. 6 " 阅读全文
posted @ 2018-10-28 23:48 adminyzz 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 205. Isomorphic Strings 判断两个字符串的是否同形。 利用字典,字符串中每一个不同的字符对应一个数字,最后数字相同则表示字符串同形。 更简单的办法:判断len(set(s)) len(set(t)) len(set(zip(s,t))) 是否相等 1 class Solutio 阅读全文
posted @ 2018-10-27 22:51 adminyzz 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 202. Happy Number 最终平方和为1则为快乐肥宅数!循环过程中可建立一个数组,存储中间结果。 1 class Solution(object): 2 def isHappy(self, n): 3 """ 4 :type n: int 5 :rtype: bool 6 """ 7 re 阅读全文
posted @ 2018-10-26 19:47 adminyzz 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 190.Reverse Bits 先转化为2进制,取[2:](排除0b),转换成列表,填充0,join,int转换 1 class Solution: 2 # @param n, an integer 3 # @return an integer 4 def reverseBits(self, n) 阅读全文
posted @ 2018-10-25 19:00 adminyzz 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 169.Majority Element 建立字典,统计数字数目,满足要求的输出。 1 class Solution(object): 2 def majorityElement(self, nums): 3 """ 4 :type nums: List[int] 5 :rtype: int 6 " 阅读全文
posted @ 2018-10-24 21:00 adminyzz 阅读(70) 评论(0) 推荐(0) 编辑