Leetcode
文章平均质量分 59
伊萨卡钢琴家
这个作者很懒,什么都没留下…
展开
-
3Sum
原题目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.For example, given array转载 2015-03-28 12:39:04 · 266 阅读 · 0 评论 -
Leetcode@word search
For this problem, it is a common depth first search problem, and use the visited boolean array to judge if the char element has been visited before. one problem I meet if that start means the number原创 2016-01-20 06:42:53 · 241 阅读 · 0 评论 -
Leetcode java Word Search2
/**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 ver原创 2016-01-20 06:54:44 · 354 阅读 · 0 评论 -
Leetcode @ Word Search II
Learning a new data structure trie from here http://www.toptal.com/java/the-trie-a-neglected-data-structureHere is t the program to use tire to solve this problem http://www.programcreek.com/2014/0转载 2016-01-20 07:05:47 · 490 阅读 · 0 评论 -
Subsets II @Leetcode
Subsets II //Given a collection of integers that might contain duplicates, nums, return all possible subsets.//For example, If nums = [1,2,2], a solution is: [/** [2], [1], [1,2,2],原创 2016-01-20 13:59:18 · 374 阅读 · 0 评论 -
Leetcode @ Gas Station
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原创 2016-01-20 14:41:28 · 357 阅读 · 0 评论 -
Leetcode@jump Game
jump GameGiven 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.原创 2016-01-20 14:56:35 · 238 阅读 · 0 评论 -
Leetcode@Jump Game II
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.Your goal i原创 2016-01-20 15:07:53 · 274 阅读 · 0 评论 -
Leetcode 329. Longest Increasing Path in a Matrix
329. Longest Increasing Path in a MatrixGiven an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down.原创 2016-01-21 02:55:50 · 1075 阅读 · 0 评论 -
Leetcode 130. Surrounded Regions
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.Analysis: This question i转载 2016-01-21 05:04:35 · 336 阅读 · 0 评论 -
Leetcode 328. Odd Even Linked List
328. Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes原创 2016-01-21 03:59:53 · 292 阅读 · 0 评论 -
刷题总结
1做题分几步走1 首先拿到题目先分析,搞明白题意2 然后想算法来解决3 编写code,尝试写的快一些4 修改明显的bug,比如没有加分好,Variable name 写错, 和method 中的参数对应不上,for循环中时候有错误导致溢出,然后用一个例子自己测试一下自己写的程序。由于Leetcode 或者 interview question 问题都比较短,所以有足够的时间自己原创 2016-01-21 13:40:17 · 337 阅读 · 0 评论 -
Leetcode 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 ( and ).原创 2016-01-21 13:42:31 · 467 阅读 · 0 评论 -
Leetcode 310. Minimum Height Trees
310. Minimum Height TreesFor a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with转载 2016-01-21 14:04:21 · 472 阅读 · 0 评论 -
Leetcode 136. Single Number
Leetcode 136. Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.This question is so intended to examine about the bit manipulation, beca原创 2016-01-21 14:17:18 · 369 阅读 · 0 评论 -
Leetcode 137. Single Number II
Single Number IIGiven an array of integers, every element appears three times except for one. Find that single one.Analysis: given a integer, there could be 32 positions in a Integer. If the原创 2016-01-22 03:47:22 · 329 阅读 · 0 评论 -
Leetcode 190. Reverse Bits
190. Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represent原创 2016-01-22 04:22:27 · 358 阅读 · 0 评论 -
Leetcode 260. Single Number III
Single Number IIIGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.原创 2016-01-22 04:08:34 · 287 阅读 · 0 评论 -
Leetcode 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2Analysis: This question is a原创 2016-01-22 04:56:50 · 240 阅读 · 0 评论 -
Leetcode 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2016-01-22 05:05:46 · 342 阅读 · 0 评论 -
Leetcode 208. Implement Trie (Prefix Tree)
questionLeetcode 208. Implement Trie (Prefix Tree)mplement a trie with insert, search, and startsWith methods.Analysis:For the trie, we need to apply insert, search, and startWith whic原创 2016-01-23 04:18:01 · 273 阅读 · 0 评论 -
Leetcode 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5原创 2016-01-23 05:40:50 · 293 阅读 · 0 评论 -
Leetcode 295. Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median原创 2016-01-23 06:00:11 · 286 阅读 · 0 评论 -
Leetcode 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-01-23 06:36:47 · 241 阅读 · 0 评论 -
Leetcode 62. 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原创 2016-01-23 13:54:18 · 209 阅读 · 0 评论 -
Leetcode 63. Unique Paths II
question: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 respect原创 2016-01-23 14:03:28 · 230 阅读 · 0 评论 -
Leetcode 1. Two Sum
questionGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to t原创 2016-01-23 14:07:00 · 237 阅读 · 0 评论 -
Leetcode 42. 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]原创 2016-01-23 14:26:28 · 207 阅读 · 0 评论 -
Leetcode 54. 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 ]]原创 2016-01-23 14:41:49 · 374 阅读 · 0 评论 -
Leetcode 73. 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.public class Solution { public void setZeroes(int[][] matrix) { int m = matrix.length; if原创 2016-01-23 14:48:01 · 233 阅读 · 0 评论 -
Leetcode 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.原创 2016-01-23 15:01:55 · 225 阅读 · 0 评论 -
Leetcode 33. Search in Rotated Sorted Array
Leetcode 33. Search in Rotated Sorted Arrayquestion: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原创 2016-01-24 05:08:13 · 265 阅读 · 0 评论 -
Leetcode 81. Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the原创 2016-01-24 05:22:49 · 248 阅读 · 0 评论 -
Leetcode 74. 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原创 2016-01-24 05:29:47 · 227 阅读 · 0 评论 -
Leetcode 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].The idea is from http://www.programcreek.com/原创 2016-01-24 05:41:38 · 264 阅读 · 0 评论 -
Leetcode 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O原创 2016-01-24 05:48:27 · 249 阅读 · 0 评论 -
Leetcode 128. Longest Consecutive Sequence
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原创 2016-01-24 06:07:37 · 217 阅读 · 0 评论 -
Leetcode 75. 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原创 2016-01-24 09:24:59 · 492 阅读 · 0 评论 -
Leetcode 27. 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.T原创 2016-01-24 09:52:23 · 240 阅读 · 0 评论 -
Leetcode Array题型总结
Dynamic Programming62. Unique Paths https://leetcode.com/problems/unique-paths/63. Unique Paths II https://leetcode.com/problems/unique-paths-ii/120. Triangle h原创 2016-01-24 09:51:12 · 433 阅读 · 0 评论