- 博客(39)
- 收藏
- 关注
转载 删除指定节点Remove Nth Node From End of List
Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the se...
2015-01-23 17:59:00
111
转载 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 following two linked lists:A: a1 → a2 ↘...
2015-01-23 17:24:00
117
转载 链表经典题Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Hide TagsLinked List/...
2015-01-23 16:54:00
184
转载 删除重复节点 Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3....
2015-01-23 15:23:00
96
转载 Permutations II 去掉重复的全排列
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[...
2014-11-22 19:08:00
83
转载 Permutations 全排列 回溯
Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].Hide ...
2014-11-21 23:58:00
84
转载 Subsets II
Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not ...
2014-11-21 12:51:00
67
转载 Subsets 集合子集 回溯
Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets....
2014-11-21 00:20:00
95
转载 Sum Root to Leaf Numbers深度优先计算路径和
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123....
2014-11-20 14:42:00
84
转载 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 andsum = 22, 5 ...
2014-11-20 13:55:00
102
转载 Convert Sorted Array to Binary Search Tree转换成平衡二查搜索树
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.二分递归转换Hide TagsTreeDepth-first Search/** * Definition for bina...
2014-11-20 13:04:00
87
转载 Balanced Binary Tree 判断平衡二叉树
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynod...
2014-11-20 00:44:00
99
转载 Minimum Depth of Binary Tree最短深度
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Hide TagsTreeDep...
2014-11-19 23:01:00
82
转载 Maximum Depth of Binary Tree 树的最大深度
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Hide TagsTreeDep...
2014-11-19 22:07:00
79
转载 深度优先搜索(Depth-First-Search)精髓
引例:迷宫问题首先我们来想象一只老鼠,在一座不见天日的迷宫内,老鼠在入口处进去,要从出口出来。那老鼠会怎么走?当然可以是这样的:老鼠如果遇到直路,就一直往前走,如果遇到分叉路口,就任意选择其中的一条继续往下走,如果遇到死胡同,就退回到最近的一个分叉路口,选择另一条道路再走下去,如果遇到了出口,老鼠的旅途就算成功结束了。深度优先搜索的基本原则就是这样:按照某种条件往前试探搜索,如果前...
2014-11-19 19:27:00
196
转载 Path Sum 深度搜索
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 ...
2014-11-19 19:14:00
75
转载 Same Tree 深度优先
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value....
2014-11-19 18:21:00
73
转载 Symmetric Tree 深度优先搜索
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3...
2014-11-19 18:10:00
69
转载 Length of Last Word输出最后单词的字母个数
Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note:...
2014-11-18 20:30:00
115
转载 Add Binary字符数字相加,字符串合成
Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".Hide TagsMathStringclass Solution {public...
2014-11-18 19:53:00
115
转载 Implement strStr() 字符串匹配
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had bee...
2014-11-18 19:07:00
90
转载 Valid Parentheses
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"a...
2014-11-12 17:06:00
54
转载 Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray[4...
2014-11-08 16:13:00
61
转载 Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal tom+n) to hold additional ele...
2014-11-07 23:40:00
69
转载 Minimum Path Sum
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either dow...
2014-11-07 21:20:00
57
转载 Search a 2D Matrix
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first...
2014-11-06 21:10:00
52
转载 Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is...
2014-11-06 15:30:00
45
转载 Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the ar...
2014-11-06 15:04:00
45
转载 Search Insert Position
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is not found...
2014-11-06 15:03:00
51
转载 Sort Colors
Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the intege...
2014-11-06 15:01:00
69
转载 Triangle
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],...
2014-11-06 15:00:00
74
转载 Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the g...
2014-11-06 14:53:00
56
转载 Unique Paths
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach t...
2014-11-06 14:52:00
52
转载 Pascal's Triangle II
Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extra space?class Solution ...
2014-11-06 14:51:00
49
转载 Pascal's Triangle
GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution {p...
2014-11-06 14:45:00
53
转载 Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution {...
2014-11-06 14:44:00
54
转载 Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should return length =5, and A is now[1,1,2,2,3...
2014-11-06 14:40:00
49
转载 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place w...
2014-11-06 14:38:00
56
转载 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length....
2014-11-06 13:57:00
50
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人