自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 CODE 81: N-Queens II

Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. public int totalNQueens(int n) { // Note: The Solution objec

2013-10-16 22:41:02 716

原创 CODE 82: N-Queens

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.Eac

2013-10-16 19:33:03 584

原创 CODE 80: 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,−1,2,1] ha

2013-10-13 22:07:19 469

原创 CODE 79: Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]

2013-10-12 23:11:27 522

原创 CODE 78: 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

2013-10-11 21:53:04 464

原创 CODE 76: Insert Interval

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E

2013-10-11 20:22:05 450

原创 CODE 77: Merge Intervals

Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]. public ArrayList merge(ArrayList intervals) {

2013-10-10 23:20:18 479

原创 CODE 75: 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

2013-10-10 21:32:13 471

原创 CODE 73: Permutation Sequence

The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3

2013-10-09 19:41:45 554

原创 CODE 72: Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL. public ListNode rotateRight(Li

2013-10-09 00:06:37 473

原创 CODE 70: 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

2013-10-07 23:22:17 1088

原创 CODE 71: 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

2013-10-07 22:36:05 559

原创 CODE 69: 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

2013-10-07 22:13:22 541

原创 CODE 68: 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. public ListNode mergeTwoLists(ListNode l1, ListNode

2013-10-07 20:07:42 501

原创 CODE 67: Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". public String addBinary(String a, String b) { // Note: The Solution object

2013-10-07 19:59:34 584

原创 CODE 66: Valid Number

Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous.

2013-10-07 19:34:22 954

原创 CODE 65: Plus One

Given a number represented as an array of digits, plus one to the number. public int[] plusOne(int[] digits) { // Start typing your Java solution below // DO NOT write main() function int c

2013-10-07 15:37:17 643

原创 CODE 64: Text Justification

Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i

2013-10-07 11:37:23 528

原创 CODE 63: Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x. public int sqrt(int x) { // Note: The Solution object is instantiated only once and is reused by // each test case. i

2013-10-06 17:19:33 472

原创 CODE 62: Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? public int climbStairs(in

2013-10-06 17:05:50 570

原创 CODE 61: Simplify Path

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did

2013-10-06 16:23:58 531

原创 CODE 60: 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(mn) s

2013-10-05 10:07:35 469

原创 CODE 59: 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

2013-10-04 22:22:18 507

原创 CODE 58: 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 0,

2013-10-04 20:52:26 601

原创 CODE 57: Minimum Window Substring

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".

2013-10-04 11:01:07 490

原创 CODE 56: Combinations

Given two integers n and k, return all possible combinations ofk 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],]

2013-10-03 21:07:26 438

原创 CODE 55: 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 example

2013-10-01 23:25:33 522

原创 CODE 54: Word Search

Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n

2013-10-01 22:42:51 404

原创 CODE 50: Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-

2013-09-29 22:44:54 531

原创 CODE 51: Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. public ListNode dele

2013-09-29 22:04:44 429

原创 CODE 48: Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. public int maximalRectangle(char[][] matrix) { // Start typing your Java sol

2013-09-28 22:06:31 377

原创 CODE 49:Largest Rectangle in Histogram

public int largestRectangleArea(int[] height) { // Start typing your Java solution below // DO NOT write main() function if (null == height || height.length <= 0) { return 0; } int max =

2013-09-27 23:30:26 485

原创 CODE 47: 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

2013-09-25 22:30:06 684

原创 CODE 45: 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 to hold additional elements from B. The number of elements initialized in A

2013-09-23 22:43:47 400

原创 CODE 44: Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of

2013-09-22 22:52:19 508

原创 CODE 43: Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu

2013-09-22 21:55:13 492

原创 CODE 40: Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order

2013-09-21 21:09:27 520

原创 CODE 39: Submission Details

Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio

2013-09-21 20:00:05 537

原创 CODE 46: Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr

2013-09-21 19:51:04 684

原创 CODE 37: Unique Binary Search Trees II

Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3

2013-09-21 11:01:06 611

空空如也

空空如也

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

TA关注的人

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