- 博客(69)
- 资源 (1)
- 收藏
- 关注
原创 [leet code] Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i
2014-01-29 08:10:09 813
原创 [leet code] 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 as 1 and 0 respectively in the
2014-01-29 01:15:44 1575
原创 [leet code] Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST=================Analysis:Rules of height balanced BST:1. all node values in left su
2014-01-28 01:41:36 896
原创 [leet code] N-Queens & II
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.
2014-01-27 08:17:18 855
原创 [CrackCode] 2.4 Add two numbers and return the sum as a linked list
You have two numbers represented by a linked list, where each node contains a single digit The digits are stored in reverse order, such that the 1’s digit is at the head of the list Write a function t
2014-01-27 04:16:03 1054
原创 [CrackCode] 2.3 Delete a node in the middle of a single linked list
Implement an algorithm to delete a node in the middle of a single linked list, givenonly access to that nodeEXAMPLEInput: the node ‘c’ from the linked list a->b->c->d->eResult: n
2014-01-27 01:44:07 799
原创 [CrackCode] 2.2 Find the nth to last element of a singly linked list
Implement an algorithm to find the nth to last element of a singly linked list.==========Analysis:Similar problem as "Remove Nth Node From End of List" in LeetCode. Idea is to use two poi
2014-01-27 01:06:11 978
原创 [CrackCode] 2.1 Remove duplicates from an unsorted linked list
Write code to remove duplicates from an unsorted linked listFOLLOW UPHow would you solve this problem if a temporary buffer is not allowed? ==========Analysis:If extra space allowed,
2014-01-27 00:27:01 1307
原创 [CrackCode] 1.4 Write a method to decide if two strings are anagrams or not
Write a method to decide if two strings are anagrams or not============Analysis:Solution1, no extract space O(n^2).Solution 2 and 3, O(n).public class Answer { public static boolean solut
2014-01-26 07:19:17 875
原创 [CrackCode] 1.3 Remove the duplicate characters in a string
Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer NOTE: One or two additional variables are fineAn extra copy of the array is not.
2014-01-25 03:24:30 989
原创 [CrackCode] 1.2 Write code to reverse a C-Style String
Write code to reverse a C-Style String (C-String means that “abcd” is represented asfive characters, including the null character ) ===========Analysis:Basic idea is to setup two point
2014-01-25 01:59:37 2776
原创 [leet code] 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 of O(log n).If the target is not found
2014-01-23 05:02:03 522
原创 [leet code] 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.For exa
2014-01-23 02:10:14 1449
原创 [leet code] 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 / \
2014-01-22 07:24:38 634
原创 [leet code] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.==========Analysis:Nothing special, just implement how we manually count that. Idea of which is to use the
2014-01-22 05:54:36 656
原创 [leet code] Length of Last Word
Given a string s consists 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: A word is
2014-01-22 02:06:49 537
原创 [leet code] 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2014-01-22 01:22:39 818
原创 [leet code] 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 "()[]{}" are all va
2014-01-21 06:47:33 554
原创 [leet code] Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2014-01-21 05:35:07 1021
原创 [leet code] Sum Root to Leaf Numbers
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 tota
2014-01-21 01:30:54 3811
原创 [leet code] 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.===========Analysis:1. Recursive
2014-01-21 00:49:20 603
原创 [leet code] Populating Next Right Pointers in Each Node II
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
2014-01-19 08:25:54 635
原创 [leet code] Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin
2014-01-19 04:17:33 678
原创 [leet code] Search in Rotated Sorted Array & II
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2014-01-19 01:08:52 2265
原创 [leet code] Pascal's Triangle II
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?===========O
2014-01-18 06:57:50 3088
原创 [leet code] Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2014-01-18 04:49:26 15462
原创 [leet code] Remove Nth Node From End of List
Given a linked list, remove the nth node 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 second node from the end, the
2014-01-18 01:40:55 5141
原创 [leet code] 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 tree and sum
2014-01-18 00:32:03 728
原创 [leet code] Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2014-01-17 11:04:41 820
原创 [leet code] Remove Duplicates from Sorted Array I & II
Remove Duplicates from Sorted Array I :Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for
2014-01-16 11:56:23 1984
原创 [leet code] Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2014-01-16 07:00:06 1787
原创 [leet code] Plus One
Given a number represented as an array of digits, plus one to the number.==============Analysis: There are 3 cases of this problem:1. just add one at the lowest digit, e.g. 123 + 1 = 124. 2.
2014-01-16 04:15:15 722
原创 [leet code] Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2014-01-16 01:31:10 988
原创 [leet code] Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m
2014-01-15 06:58:09 766
原创 [leet code] 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
2014-01-15 06:26:47 3035
原创 [leet code] Binary Tree Postorder Traversal
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 solut
2014-01-15 05:24:20 1989
原创 [leet code] Linked List Cycle II
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?Extension from problem Linked List Cycle.
2014-01-15 01:17:10 1461
原创 [leet code] Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Without followup, we can directly create a new n x
2014-01-14 08:11:11 935
原创 [leet code] Unique Paths
A robot is located at the top-left corner of a m x n grid (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 the
2014-01-14 02:22:28 3191
原创 [leet code] Sort Colors
Given an array with n objects 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 integers
2014-01-14 00:55:50 645
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人