03 2016 档案

摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. 阅读全文
posted @ 2016-03-30 14:08 背锅侠 阅读(220) 评论(0) 推荐(0)
摘要:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins tha... 阅读全文
posted @ 2016-03-29 14:39 背锅侠 阅读(183) 评论(0) 推荐(0)
摘要:Sort a linked list in O(n log n) time using constant space complexity.排序一个链表可以类似于插入排序那样,这样需要每次都从头开始遍历找到插入位置,所以复杂度是O(n^2),所以这样是不行的,数组中的排序方法里快排... 阅读全文
posted @ 2016-03-23 22:35 背锅侠 阅读(252) 评论(0) 推荐(0)
摘要:198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the o... 阅读全文
posted @ 2016-03-20 21:21 背锅侠 阅读(368) 评论(0) 推荐(0)
摘要:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You ... 阅读全文
posted @ 2016-03-20 17:15 背锅侠 阅读(129) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6The f... 阅读全文
posted @ 2016-03-17 19:17 背锅侠 阅读(131) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.clas... 阅读全文
posted @ 2016-03-09 16:37 背锅侠 阅读(174) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.class... 阅读全文
posted @ 2016-03-09 16:35 背锅侠 阅读(147) 评论(0) 推荐(0)
摘要:Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 uniq... 阅读全文
posted @ 2016-03-09 15:50 背锅侠 阅读(150) 评论(0) 推荐(0)
摘要:解决二叉树的很多问题的方案都是基于对二叉树的遍历。遍历二叉树的前序,中序,后序三大方法算是计算机科班学生必写代码了。其递归遍历是人人都能信手拈来,可是在手生时写出非递归遍历恐非易事。正因为并非易事,所以网上出现无数的介绍二叉树非递归遍历方法的文章。可是大家需要的真是那些非递归遍历代... 阅读全文
posted @ 2016-03-09 15:24 背锅侠 阅读(314) 评论(0) 推荐(0)
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “T... 阅读全文
posted @ 2016-03-09 14:27 背锅侠 阅读(196) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example: Given the below binary tre... 阅读全文
posted @ 2016-03-09 11:30 背锅侠 阅读(130) 评论(0) 推荐(0)
摘要:Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given bina... 阅读全文
posted @ 2016-03-08 22:00 背锅侠 阅读(151) 评论(0) 推荐(0)
摘要:http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html 阅读全文
posted @ 2016-03-08 21:30 背锅侠 阅读(185) 评论(0) 推荐(0)
摘要:快慢指针是链表中常用的技巧,反转链表也是常用算法之一。 使用p和q两个指针配合工作,使得两个节点间的指向反向,同时用r记录剩下的链表。p = head; q = head->next; head->next = NULL; 现在进入循环体,这是第一次循环。 r = q->nex... 阅读全文
posted @ 2016-03-08 19:59 背锅侠 阅读(183) 评论(0) 推荐(0)
摘要:1、欧几里德算法(辗转相除法)最大公约数 greatest common divisor,简写为gcd;或highestcommon factor,简写为hcf 最小公倍数 最小公倍数(Least Common Multiple,缩写L.C.M.)最小公倍数=两数的乘积/最大公约数... 阅读全文
posted @ 2016-03-05 20:35 背锅侠 阅读(966) 评论(0) 推荐(0)
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of ... 阅读全文
posted @ 2016-03-05 20:20 背锅侠 阅读(127) 评论(0) 推荐(0)
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should prese... 阅读全文
posted @ 2016-03-04 13:00 背锅侠 阅读(132) 评论(0) 推荐(0)
摘要:iven a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3... 阅读全文
posted @ 2016-03-04 09:44 背锅侠 阅读(204) 评论(0) 推荐(0)
摘要:问题描述Given a singly linked list, determine if it is a palindrome. 【解题思路】 1. 遍历链表,快慢指针,找到链表后半部分。 2. 反转链表,可以参考Reverse Linked List。 3. 然后比较前半部... 阅读全文
posted @ 2016-03-02 21:36 背锅侠 阅读(132) 评论(0) 推荐(0)