自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(21)
  • 收藏
  • 关注

原创 64. Minimum Path Sum

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.Note: You can only move either down or right at any

2016-03-30 14:08:03 163

原创 322. Coin Change

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money c

2016-03-29 14:39:58 173

原创 148. Sort List

Sort a linked list in O(n log n) time using constant space complexity.排序一个链表可以类似于插入排序那样,这样需要每次都从头开始遍历找到插入位置,所以复杂度是O(n^2),所以这样是不行的,数组中的排序方法里快排和堆排并不适合。如果有两个排序的链表,将他们进行融合是很容易的,所以采用分治法,是可以很快求解的。所以答案如下:/**

2016-03-23 22:35:34 190

原创 caffe+Ubuntu14.04.10 +cuda7.0/7.5+CuDNNv4 安装

特别说明: 0. Caffe 官网地址:http://caffe.berkeleyvision.org/ 1. 本文为作者亲自实验完成,但仅限用于学术交流使用,使用本指南造成的任何不良后果由使用者自行承担,与本文作者无关,谢谢!为保证及时更新,转载请标明出处,谢谢! 2. 本文旨在为新手提供一个参考,请高手勿要吐槽,有暴力倾向者,请绕道,谢谢! 3. 本文使用2016年3月22日下载的caf

2016-03-22 22:08:06 1686

原创 337. House Robber III(包含I和II)

198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is tha

2016-03-20 21:21:42 424

原创 318. Maximum Product of Word Lengths

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 may assume that each word will contain only lower case lette

2016-03-20 17:15:26 222

原创 114. Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2

2016-03-17 19:17:31 195

原创 106. Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.class Solution {public: TreeNode* buildTree(vector<int>& in

2016-03-09 16:37:02 151

原创 105. Construct Binary Tree from Preorder and Inorder Traversal

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 Solution {public: /* from Preorder and Inorder Travers

2016-03-09 16:35:56 218

原创 96. Unique Binary Search Trees(I 和 II)

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 unique BST’s. 1 3 3 2 1 \ /

2016-03-09 15:50:41 196

转载 更简单的非递归遍历二叉树的方法

解决二叉树的很多问题的方案都是基于对二叉树的遍历。遍历二叉树的前序,中序,后序三大方法算是计算机科班学生必写代码了。其递归遍历是人人都能信手拈来,可是在手生时写出非递归遍历恐非易事。正因为并非易事,所以网上出现无数的介绍二叉树非递归遍历方法的文章。可是大家需要的真是那些非递归遍历代码和讲述吗?代码早在学数据结构时就看懂了,理解了,可为什么我们一而再再而三地忘记非递归遍历方法,却始终记住了递归遍历方法

2016-03-09 15:24:08 295

原创 236. Lowest Common Ancestor of a Binary Tree

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: “The lowest common ancestor is defined between two nodes v and

2016-03-09 14:27:20 216

原创 113. Path Sum II

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 tree and sum = 22, 5 / \

2016-03-09 11:30:05 180

原创 102. Binary Tree Level Order Traversal

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \

2016-03-08 22:00:38 187

转载 Morris Traversal 方法遍历二叉树(非递归、不用栈,O(1)空间)

http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html

2016-03-08 21:30:44 174

原创 206. Reverse Linked List

快慢指针是链表中常用的技巧,反转链表也是常用算法之一。 使用p和q两个指针配合工作,使得两个节点间的指向反向,同时用r记录剩下的链表。p = head; q = head->next; head->next = NULL; 现在进入循环体,这是第一次循环。 r = q->next; q->next = p; p = q; q =r; 第二次循环。 r = q->n

2016-03-08 19:59:53 236

原创 欧几里德算法求解最大公约数

1、欧几里德算法(辗转相除法)最大公约数 greatest common divisor,简写为gcd;或highestcommon factor,简写为hcf 最小公倍数 最小公倍数(Least Common Multiple,缩写L.C.M.)最小公倍数=两数的乘积/最大公约数欧几里德算法(辗转相除法) 1. 欧几里德算法和扩展欧几里德算法 1). 欧几里德算法 欧几里德算法又称辗转

2016-03-05 20:35:44 725

原创 25. Reverse Nodes in k-Group

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 k then left-out nodes in the end should remain as it is.You

2016-03-05 20:20:14 163

原创 86. Partition List

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 preserve the original relative order of the nodes in each of the

2016-03-04 13:00:44 207

原创 24. Swap Nodes in Pairs

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.Your algorithm should use only constant space. You may not

2016-03-04 09:44:17 227

原创 234. Palindrome Linked List

问题描述Given a singly linked list, determine if it is a palindrome. 【解题思路】 1. 遍历链表,快慢指针,找到链表后半部分。 2. 反转链表,可以参考Reverse Linked List。 3. 然后比较前半部分和后半部分的val值。快慢指针是链表中常用的技巧,反转链表也是常用算法之一。class Solution {

2016-03-02 21:36:43 221

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除