
python LeetCode
文章平均质量分 66
Tear_code
ing
展开
-
LeetCode 1. Two Sum Python Solution
此题目对应于 LeetCode 1此题目对应于1. 两数之和题目要求: Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly...原创 2017-10-10 11:45:33 · 384 阅读 · 0 评论 -
LeetCode 86. Partition List 链表的划分 Python Solution
此题目对应于86. Partition List题目要求基于一个给定的值x对链表做一个划分partition,使得小于x的放在前,大于等于x的放在后,两部分各自保持原有顺序。解题思路很简单:1.设置两个链表,一个存放小于x的元素,一个存放大于等于x的元素2.合并两个链表,这里需要注意的是需要对第二个辅助链表的表尾进行制空,以防止出现从头到尾的循环链表。下面附上python代码:原创 2017-11-02 16:54:15 · 471 阅读 · 0 评论 -
用python介绍4种常用的单链表翻转的方法。
python,单链表反转,LeetCode原创 2017-09-28 20:31:28 · 6742 阅读 · 0 评论 -
LeetCode 144,94,145,102,103 Binary Tree Traversal 二叉树遍历 Python Solution
这篇文章汇总介绍 LeetCode 上的二叉树的遍历题目,由于内容可能比较多,所以持续更新中ing首先是94. Binary Tree Inorder Traversal题目要求:原创 2017-10-23 09:37:07 · 1351 阅读 · 0 评论 -
LeetCode 114. Flatten Binary Tree to Linked List 拉平二叉树 Python Solution
此题目对应于LeetCode 114题目要求:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t原创 2017-10-27 09:23:40 · 270 阅读 · 0 评论 -
LeetCode 136. Single Number找数组单元素 Python Solution
此题目对应于 LeetCode 136题目要求:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you原创 2017-10-10 10:03:04 · 356 阅读 · 0 评论 -
LeetCode 105,106. Construct Binary Tree 重建二叉树 Python Solution
此题目对应于 LeetCode 105题目要求:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.重建二叉树是二叉树的基本操作,通常给出二叉原创 2017-10-16 09:31:55 · 1271 阅读 · 0 评论 -
LeetCode 148. Sort List 单链表排序 Python Solution
此题目对应于LeetCode 148题目要求:Sort a linked list in O(n log n) time using constant space complexity.用O(n log n) 的排序算法,很容易让人想到用递推去做。思路就是将单链表一分为二划分成两个子问题,然后递归调用算法,最后在做一个对两个有序的单链表的合并操作(O(n))。原创 2017-10-20 21:00:31 · 1535 阅读 · 0 评论 -
Python求一个数对应二进制最低位为1对应的数字lowbit
要求一个数对应二进制最低位为1对应的数字lowbit,如lowbit(5),5的二进制位101,对应的结果就,001即1,lowbit(4),4的二进制位100,对应的结果就,100即4。由于计算机采用二进制补码作为数学运算,所以可以用x&-x来求得举例:x=1,原码0001,以4位表示,x的补码就是0001, -x=-1,原码1001,-x的补码就是1111,所以x&-x =原创 2017-10-10 10:51:32 · 3282 阅读 · 1 评论 -
LeetCode 260. Single Number III Python Solution
此题目对应于 LeetCode 260题目要求:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only原创 2017-10-11 17:01:59 · 424 阅读 · 0 评论 -
图核graph kernel方法Python工具包graphkernels的安装和使用
图核graph kernel是一种有效的图结构相似度的近似度量方式,针对不同的图结构(labeled graphs, weighted graphs, directed graphs, etc.) 有不同的Graph kernel。这里,我们不介绍graph kernel的算法理论,只是简单介绍下其Python工具包graphkernels的安装和使用。graphkerne原创 2017-11-21 11:43:40 · 10116 阅读 · 4 评论