随笔分类 -  算法

摘要:"148. Sort List" Sort a linked list in O(n log n) time using constant space complexity. Solution 利用归并排序的思想 Definition for singly linked list. class Li 阅读全文
posted @ 2017-01-17 22:15 BinWone 阅读(119) 评论(0) 推荐(0)
摘要:"160. Intersection of Two Linked Lists" Write a program to find the node at which the intersection of two singly linked lists begins. For example, the 阅读全文
posted @ 2017-01-03 21:47 BinWone 阅读(146) 评论(0) 推荐(0)
摘要:"328. Odd Even Linked List" Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about 阅读全文
posted @ 2017-01-03 17:17 BinWone 阅读(125) 评论(0) 推荐(0)
摘要:"234. Palindrome Linked List" Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 判断一 阅读全文
posted @ 2017-01-03 12:00 BinWone 阅读(125) 评论(0) 推荐(0)
摘要:Trie树:字典查找树。 "208. Implement Trie (Prefix Tree)" Implement a trie with , , and methods. Note: You may assume that all inputs are consist of lowercase 阅读全文
posted @ 2016-12-28 20:39 BinWone 阅读(171) 评论(0) 推荐(0)
摘要:题目:n个数字(0,1,…,n 1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字)。当一个数字删除后,从被删除数字的下一个继续删除第m个数字。求出在这个圆圈中剩下的最后一个数字。 Solution 阅读全文
posted @ 2016-12-15 12:05 BinWone 阅读(190) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/kth largest element in an array/ Find the kth largest element in an unsorted array. Note that it is the kth largest elem 阅读全文
posted @ 2016-12-09 15:24 BinWone 阅读(170) 评论(0) 推荐(0)
摘要:剑指Offer:面试题43 把n个骰子扔在地上,所有骰子朝上一面的点数之和为s。求s的所有可能值出现的次数。 比如扔两个骰子,s的可能值为2 12,出现的次数分别为:1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1 Solution 在一次循环中,一个数组中的第n个元素表示骰子和为n出 阅读全文
posted @ 2016-12-05 13:47 BinWone 阅读(205) 评论(0) 推荐(0)
摘要:图 1.DFS & BFS 深度优先算法 : (1)访问初始顶点v并标记顶点v已访问。 (2)查找顶点v的第一个邻接顶点w。 (3)若顶点v的邻接顶点w存在,则继续执行;否则回溯到v,再找v的另外一个未访问过的邻接点。 (4)若顶点w尚未被访问,则访问顶点w并标记顶点w为已访问。 (5)继续查找顶点 阅读全文
posted @ 2016-12-02 20:11 BinWone 阅读(178) 评论(0) 推荐(0)
摘要:有序数组旋转相关问题。 "153. Find Minimum in Rotated Sorted Array" Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., might become 阅读全文
posted @ 2016-12-02 11:32 BinWone 阅读(165) 评论(0) 推荐(0)
摘要:二叉树 参考:http://blog.csdn.net/luckyxiaoqiang/article/details/7518888 题目列表: 1. "求二叉树中的节点个数" 2. 求二叉树的深度 3. 前序遍历,中序遍历,后序遍历 4. 分层遍历二叉树(按层次从上往下,从左往右) 5. 将二叉查 阅读全文
posted @ 2016-12-01 16:56 BinWone 阅读(274) 评论(0) 推荐(0)
摘要:"101. Symmetric Tree" 判断一棵二叉树是不是镜像对称的。 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, thi 阅读全文
posted @ 2016-11-30 13:03 BinWone 阅读(385) 评论(0) 推荐(0)
摘要:题意 输入两棵二叉树A和B,判断B是不是A的子结构。 Solution 阅读全文
posted @ 2016-11-30 10:26 BinWone 阅读(373) 评论(0) 推荐(0)
摘要:合并两个已排序的链表。 https://leetcode.com/problems/merge two sorted lists/ Merge two sorted linked lists and return it as a new list. The new list should be ma 阅读全文
posted @ 2016-11-29 19:21 BinWone 阅读(147) 评论(0) 推荐(0)
摘要:两个链表反转问题。 "206. Reverse Linked List" Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you im 阅读全文
posted @ 2016-11-29 16:16 BinWone 阅读(186) 评论(0) 推荐(0)
摘要:已知先序遍历和中序遍历及已知中序遍历和后序遍历重建二叉树的Python递归和迭代解法 105. Construct Binary Tree from Preorder and Inorder Traversal https://leetcode.com/problems/construct bina 阅读全文
posted @ 2016-11-15 22:13 BinWone 阅读(864) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/lowest common ancestor of a binary tree/ Given a binary tree, find the lowest common ancestor (LCA) of two given nodes i 阅读全文
posted @ 2016-11-08 22:09 BinWone 阅读(168) 评论(0) 推荐(0)
摘要:排序 参考资料: "经典排序算法总结与实现" 1.快速排序 Python def quick_sort(ary): return qsort(ary,0,len(ary) 1) def qsort(ary,left,right): 快排函数,ary为待排序数组,left为待排序的左边界,right为 阅读全文
posted @ 2016-11-08 09:52 BinWone 阅读(249) 评论(0) 推荐(0)