- 博客(79)
- 收藏
- 关注
原创 221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0
2016-12-10 16:39:14
209
原创 146. LRU Cache
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
2016-12-09 14:04:33
242
原创 211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only lett
2016-12-09 08:25:07
278
原创 208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode { boolean isWord = false; // Stri
2016-12-09 08:23:32
190
原创 274,275. H-Index I, II
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A
2016-12-08 13:09:40
239
原创 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/**
2016-12-05 10:48:47
190
原创 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be
2016-12-05 10:15:43
172
原创 10. Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st
2016-12-05 07:58:50
311
原创 301. Remove Invalid Parentheses
题目:Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses
2016-12-05 04:46:37
199
原创 91. 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
2016-12-05 03:04:28
221
原创 314. Binary Tree Vertical Order Traversal
题目:Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be fr
2016-12-04 08:59:10
232
原创 325. Maximum Size Subarray Sum Equals k
题目Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given nums = [1, -1, 5, -2, 3], k = 3,return 4.
2016-12-04 08:45:51
232
原创 394. Decode String
Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is
2016-11-17 02:28:29
191
原创 164. Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements
2016-11-13 05:00:17
242
原创 373. Find K Pairs with Smallest Sums
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from the first array and one element from the second a
2016-11-08 09:00:24
177
原创 Heap & Priority Queue
Heap: array implementationint[] heap, int heapSize = 0;parent and children: parent(i)=i/2; children(i) = {ix2, ix2+1}insert(int a): bubble-up private static void insert(int a, int[] h
2016-11-08 08:47:53
336
原创 374,375. Guess Number Higher or Lower I,II
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number I pi
2016-11-03 14:22:42
283
原创 32. Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",
2016-11-03 01:07:03
187
原创 31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible
2016-11-02 16:19:50
222
原创 30. Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and
2016-11-01 15:15:46
177
原创 287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,
2016-11-01 01:18:37
167
原创 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.思路:a^b异或等于无进位的加法,(a&b)解法一:public class Solution {
2016-11-01 00:15:57
161
原创 223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota
2016-10-27 07:48:56
181
原创 217, 219,220. Contains Duplicate I, II, III
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2016-10-27 01:40:41
296
原创 209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3
2016-10-22 02:25:28
177
原创 207,210. Course Schedule I, II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2016-10-21 16:16:21
280
原创 206. Reverse Linked List
Reverse a singly linked list./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solu
2016-10-21 15:35:17
139
原创 205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2016-10-21 09:13:03
160
原创 204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.思路: 从前向后扫描,第一次遇到没标记的应该是没有因子的质数。然后把后面所有这个质数的倍数都标记了。 public int countPrimes(int n) { if(n<2) retur
2016-10-21 08:54:44
154
原创 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition for si
2016-10-20 07:27:44
185
原创 202. Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2016-10-20 07:23:00
195
原创 201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.思路:从左到右比较m和n的二进制数,相同的base加起来,直到出现不同的base,停止比较,因为后面一定是0,1交错的,而前面的一定是相同的(比较过来的),只要返回这些相同部分。public class
2016-10-20 06:59:38
174
原创 200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2016-10-20 05:25:37
166
原创 198. House Robber
You 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 that adjacent house
2016-10-20 04:59:55
184
原创 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000
2016-10-20 02:37:21
165
原创 121.122.123.188. Best Time to Buy and Sell Stock I II III IV
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),
2016-10-18 08:23:58
300
原创 283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you
2016-10-18 07:48:28
147
原创 190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010
2016-10-18 02:28:22
264
原创 189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Try to come up as many solutions as you can,
2016-10-14 09:11:08
178
原创 187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2016-10-12 07:26:07
145
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人