自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(190)
  • 资源 (1)
  • 收藏
  • 关注

原创 LeetCode: Reverse Words in a String [151]

【题目】Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes a word?A sequence of non-space characters constitutes a word.

2014-07-01 19:40:35 1144

原创 LeetCode: Evaluate Reverse Polish Notation [150]

【题目】Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/

2014-07-01 19:38:28 996

原创 LeetCode: Max Points on a Line [149]

【题目】Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.【题意】 给定一堆点,要求找出一条之前上的最大点数【思路】 没什么好的方法,从每个点P出发,遍历所有的情况 从每个点P出发,斜率相同的点即为统一之前上的点 注意两种特殊情况: 1. 两个点重合(即为同一个点)

2014-07-01 19:34:48 1088

原创 LeetCode: Sort List [148]

【题目】 Sort a linked list in O(n log n) time using constant space complexity.【题意】 排序一个链表,要求时间复杂度O(nlogn),使用常量空间【思路】 nlogn的复杂度,用归并排序求解

2014-07-01 19:32:12 932

原创 LeetCode: Insertion Sort List [147]

【题目】Sort a linked list using insertion sort.【题意】 用插入排序方法排序链表【思路】 直接搞

2014-07-01 19:30:07 902

原创 LeetCode: LRU Cache [146]

【题目】Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.se

2014-06-29 11:01:35 1176

原创 LeetCode: Binary Tree Postorder Traversal [145]

【题目】Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution is trivial, could you do it iteratively?【题意】 非递归实现后续遍

2014-06-29 10:59:22 1000

原创 LeetCode: Binary Tree Preorder Traversal [144]

【题目】Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution is trivial, could you do it iteratively?【题意】 非递归返回先序遍历

2014-06-29 10:57:22 827

原创 LeetCode: Reorder List [143]

【题目】Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to {1,4,2,3}.【题意】 给定一个链表L: L0→L1→…→Ln-1→Ln,对他重新排序成L

2014-06-29 10:55:43 824

原创 LeetCode: Linked List Cycle II [142]

【题目】Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?【题意】 给定一个单向链表,如果链表有环,则返回环开始的位置。【思路】 仍然是维护两个指针, p1, p2, p1每次走一步, p2每次走两步

2014-06-29 10:53:31 773

原创 LeetCode: Linked List Cycle [141]

【题目】Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?【题意】 判断一个单向链表是否有环【思路】 维护两个指针p1和p2,p1每次向前移动一步,p2每次向前移动两步 如果p2能够追上p1,则说明链表中存在环

2014-06-28 21:02:01 802

原创 LeetCode: Word Break II [140]

【题目】Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "catsanddog",dict = ["cat", "cats", "and", "sand", "dog

2014-06-28 20:59:46 982

原创 LeetCode: Word Break [139]

【题目】Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet", "code"].Return true because "leetcode" can be segm

2014-06-28 20:57:56 900

原创 LeetCode: Copy List with Random Pointer [138]

【题目】A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.【题意】 给定一个链表,每个节点除了next指针外,还有一个random指针,指向任意的节点。 要求,复制这样的一个链表【思路】 思路

2014-06-28 20:55:11 901

原创 leetCode: Single Number II [137]

【题目】Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?【题意】 给定一个整数以外,其中除了一个整数只出现一次以外

2014-06-28 20:52:29 820

原创 LeetCode: Single Number [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 implement it without using extra memory?【题意】 给定一个整数数组,其中除了一个数以外,其他数都是成对出现的,

2014-06-25 22:12:31 864

原创 LeetCode: Candy [135]

【题目】There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candie

2014-06-25 22:10:41 897

原创 LeetCode: Gas Station [134]

【题目】There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an

2014-06-25 22:08:58 937

原创 LeetCode: Clone Graph [133]

【题目】Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each node, and , as a separator for node label and each ne

2014-06-25 22:06:18 854

原创 LeetCode: Palindrome Partitioning II [132]

【题目】Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 since the palindrome partitioning ["aa","b"] could b

2014-06-25 22:03:37 733

原创 LeetCode: Palindrome Partitioning [131]

【题目】Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"], ["a","a","b"] ]【题意】 给定一个字符串s, 要求对s进行

2014-06-25 11:07:02 801

原创 LeetCode: Surrounded Regions [130]

【题目】Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX X O XX O X XAfter running your function, the board shou

2014-06-24 19:14:06 1078

原创 LeetCode: Sum Root to Leaf Numbers [129]

【题目】Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum of all root-to-leaf numbers.For example, 1

2014-06-24 19:11:44 760

原创 LeetCode: Longest Consecutive Sequence [128]

【题目】Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4.Your algorithm should run

2014-06-24 19:09:20 742

原创 LeetCode: Word Ladder II [127]

【题目】Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start = "

2014-06-24 19:05:55 830

原创 LeetCode: Word Ladder [126]

【题目】Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:st

2014-06-24 19:01:36 918

原创 LeetCode: Valid Palindrome [125]

【题目】Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome.Note:Have you consider that the string m

2014-06-22 18:31:54 764

原创 LeetCode: Binary Tree Maximum Path Sum [124]

【题目】Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.【题意】给定一棵二叉树,找出其中路径和最大的路径,然会返回最大路径和。本题中的路径不是从根节点到叶子节点这样的传统的路

2014-06-22 18:29:37 930

原创 LeetCode: Best Time to Buy and Sell Stock III [123]

【题目】Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not engage in multiple transactions at the same time (i

2014-06-22 18:27:24 918

原创 LeetCode: Best Time to Buy and Sell Stock II [122]

【题目】Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). H

2014-06-22 18:24:48 798

原创 LeetCode: Best Time to Buy and Sell Stock [121]

【题目】Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

2014-06-06 08:20:01 830

原创 LeetCode: Triangle [120]

【题目】Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to

2014-06-06 08:18:11 824

原创 LeetCode: Pascal's Triangle II [119]

【题目】Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?【题意】 给定行索引k, k从0开始,返回该索引指向的杨辉三角的行 要求只能使用O(k)的额外空间【思路】

2014-06-06 08:15:59 851

原创 LeetCode: Pascal's Triangle [118]

【题目】Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]【题意】给定整数numRows, 要求生成杨辉三角的前numRows行【思路】 杨辉三角有以下特点: 1. 第n行有n个元素

2014-06-06 08:14:11 1163

原创 LeetCode: Populating Next Right Pointers in Each Node II [117]

【题目】Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given the following binary tre

2014-06-06 08:11:35 764

原创 LeetCode: Populating Next Right Pointers in Each Node [116]

【题目】Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be

2014-06-05 08:35:51 865

原创 LeetCode: Distinct Subsequences [115]

【题目】Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relati

2014-06-05 08:33:37 952

原创 LeetCode: Flatten Binary Tree to Linked List [114]

【题目】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 \ 3 \ 4 \

2014-06-05 08:31:35 791

原创 LeetCode: Path Sum II [113]

【题目】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 / \ 4 8 / / \ 11 13 4

2014-06-05 08:29:36 780

原创 LeetCode: Path Sum [112]

【题目】Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \

2014-06-05 08:22:26 863

PersonalRank算法的Python实现

PersonalRank算法的Python实现

2013-08-18

空空如也

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

TA关注的人

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