Bignum in Python: 加减法运算 这篇文章记录 Bignum 的加减法运算规则,理解它的最好方式就是直接阅读 Python 源码,我所查阅的版本是 Python-3.9.2,下文引用的代码和分析都基于该版本。 从 Objects/longobject.c 文件里可以找到全部相关的代码,在我们往下之前,先介绍一个预备知识。 一个加法函数可以表示为两个处理绝对值的函数: 绝对值相加的函数 绝对值相减的函数 这...
ARTS #93 Algorithm 本周选择的算法题是:Symmetric Tree。 规则 Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1: Input: root = [1,2,2,3,4,4,3] O...
Bignum in Python: 内存中的存储 这篇文章主要记录 Python 是如何在从内存中表示 Bignum 的,由于 Python 使用 Bignum 表示所有的整型,所以这也是 Python 对整型的实现方式。 我们知道 Bignum 可以表示任意长度的数字,在内存上表示为一个数组,如数字: 51090942171709440000 可以表示为: [5, 1, 0, 9, 0, 9, 4, 2, 1, 7, 1, 7,...
ARTS #92 Algorithm 本周选择的算法题是:Permutations。 规则 Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Ou...
ROT-13 在 Python 里执行 import this 会打印如下字符串: The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complica...
ARTS #91 Algorithm 本周选择的算法题是:Word Search。 规则 Given an m x n board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where “adjacen...
《发现心流》讲了什么 《发现心流》是一本结构设计得非常好的书,作者像老师一样,带领读者认识心流体验、感受心流体验,并让读者充分认识到获得心流体验的门槛极低。虽然现实生活中也存在像童年悲惨、父母虐待、生活穷困等外在因素,但强调只要带着「面对挑战、解决问题、热爱命运」的态度,相信自己拥有主动权,就能掌握自得其乐的奥秘。 心流的产生 作者将活动分成了三个大类: 生产类 - 工作、学习等活动 维持类 - ...
ARTS #90 Algorithm 本周选择的算法题是:Valid Palindrome。 规则 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we ...
Review 的意义 需要提前说明:这篇谈论的 Review 并非是 Code Review,而是 ARTS 中的 Review。 陈皓老师曾在知乎上回答过一个问题:极客时间《左耳听风》发起的ARTS挑战怎么参加?,里面谈到了 Review 的动机: Review:主要是为了学习英文,如果你的英文不行,你基本上无缘技术高手。所以,需要你阅读并点评至少一篇英文技术文章,我个人最喜欢去的地方是Medium....
ARTS #89 Algorithm 本周选择的算法题是:Merge k Sorted Lists。 规则 You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-lis...