leetcode
proudmore
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode 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] has the原创 2015-02-20 09:06:04 · 153 阅读 · 0 评论 -
Leetcode Coins in a line
There are n coins in a line. (Assume n is even). Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money w原创 2015-02-21 08:36:40 · 1256 阅读 · 0 评论 -
Leetcode Roman to Integer
[code]public class Solution { public int romanToInt(String s) { if(s==null || s.length()==0)return 0; int r=0,i=0; while(i<s.length()) { if(s.charAt(i)==原创 2015-02-19 07:08:59 · 173 阅读 · 0 评论 -
Leetcode Remove duplicates from sorted array
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 another array, you must do this in place with cons原创 2015-02-22 14:35:30 · 168 阅读 · 0 评论 -
leetcode[137] Single Number II
除了1个元素出现一次之外其他均出现2次,用exclusive or (^).general case: public class Solution { public int singleNumber(int[] A) { if (A == null) return 0; int x0 = ~0, x1 = 0, x2 = 0, t; for原创 2015-02-17 15:42:40 · 210 阅读 · 0 评论 -
leetcode Spiral Matrix
[code]public class Solution { public List<Integer> spiralOrder(int[][] matrix) { trace=new ArrayList<Integer>(); if(matrix==null || matrix.length==0 || matrix[0].length==0)return tr原创 2015-02-18 08:27:21 · 227 阅读 · 0 评论 -
Leetcode Unique Paths II
[code]public class Solution { int dp[][]; public int uniquePathsWithObstacles(int[][] obstacleGrid) { if( obstacleGrid==null || obstacleGrid.length==0 )return 0; int m=obstacleG原创 2015-02-20 08:40:41 · 204 阅读 · 0 评论 -
Leetcode Maximum product array
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest produ原创 2015-02-21 06:28:13 · 223 阅读 · 0 评论 -
Leetcode Clone Graph
[code]/** * Definition for undirected graph. * class UndirectedGraphNode { * int label; * List<UndirectedGraphNode> neighbors; * UndirectedGraphNode(int x) { label = x; neighbors = new原创 2015-02-19 07:47:19 · 172 阅读 · 0 评论 -
Leetcode Valid Parentheses
[code]public class Solution { public boolean isValid(String s) { if(s==null || s.length()==0)return true; Stack<Character> stack=new Stack<Character>(); HashMap <Character,原创 2015-02-20 07:40:40 · 310 阅读 · 0 评论 -
Leetcode Find Minimum 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).Find the minimum element.The array may contain duplicates.[code]public class S原创 2015-02-22 09:20:55 · 150 阅读 · 0 评论 -
Leetcode Integer to Roman
[code]public class Solution { public String intToRoman(int num) { StringBuffer sb=new StringBuffer(); int t=num/1000; num%=1000; for(int i=0;i<t;i++)sb.append('M');原创 2015-02-19 04:00:05 · 197 阅读 · 0 评论 -
Leetcode Evaluate Reverse Polish Notation
[code]public class Solution { public int evalRPN(String[] tokens) { if( tokens==null || tokens.length==0 )return 0; Stack<Integer> stack=new Stack<Integer>(); int i=0;原创 2015-02-20 07:24:32 · 180 阅读 · 0 评论 -
Leetcode 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.**[code]**Remove Duplicates from原创 2015-02-22 14:51:08 · 168 阅读 · 0 评论 -
Leetcode 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->1->2原创 2015-02-22 15:05:52 · 206 阅读 · 0 评论 -
Leetcode Min Stack
[code]class MinStack { ArrayList<Integer> stack=new ArrayList<Integer>(); ArrayList<Integer> mins=new ArrayList<Integer>(); public void push(int x) { stack.add(x); if(mins.i原创 2015-02-20 06:47:26 · 185 阅读 · 0 评论 -
Leetcode Search insert position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here原创 2015-02-22 08:37:33 · 172 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted Array II
Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?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].[cod原创 2015-02-22 14:42:28 · 165 阅读 · 0 评论 -
Leetcode Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).[code]public class Solution { publ原创 2015-02-25 07:28:14 · 284 阅读 · 1 评论 -
Leetcode 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 orde原创 2015-02-26 14:31:41 · 258 阅读 · 0 评论 -
Leetcode 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, 4].原创 2015-02-25 03:40:19 · 192 阅读 · 0 评论 -
Leetcode NSum 问题
Two SumGiven 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 the target, w原创 2015-02-26 08:58:23 · 433 阅读 · 0 评论 -
Leetcode 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.[code]publ原创 2015-02-26 09:06:43 · 157 阅读 · 0 评论 -
Leetcode Swap nodes in pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You原创 2015-02-28 14:59:57 · 224 阅读 · 0 评论 -
Leetcode 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 linke原创 2015-02-28 14:50:20 · 165 阅读 · 0 评论 -
Leetcode 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 gray原创 2015-02-27 13:48:33 · 199 阅读 · 0 评论 -
Leetcode Partition list
[code] Memory limit exceededpublic class Solution { public ListNode partition(ListNode head, int x) { if(head ==null || head.next==null)return head; ListNode d1=new ListNode(0), d2原创 2015-02-27 15:50:43 · 191 阅读 · 0 评论 -
Leetcode 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) { if(matrix==null)return;原创 2015-02-28 06:58:48 · 224 阅读 · 0 评论 -
Leetcode 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.[code]public class Solution { public L原创 2015-02-28 14:42:16 · 203 阅读 · 0 评论 -
Leetcode Sudoku 问题
Valid sudokuDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.public class Solut原创 2015-02-27 06:34:38 · 198 阅读 · 0 评论 -
Leetcode 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]原创 2015-02-27 07:01:14 · 222 阅读 · 0 评论 -
Leetcode 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?[code]public class Solution { public void rotate(int[][]原创 2015-02-27 07:32:32 · 180 阅读 · 0 评论 -
Leetcode Reverse linked list II
Reverse a linked list from position m to n. Do it in-place and in one-pass For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL.Note: Given m, n satisfy the fol原创 2015-02-27 14:58:25 · 183 阅读 · 0 评论 -
Leetcode Add two numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linke原创 2015-02-27 14:40:19 · 237 阅读 · 0 评论 -
Leetcode N-Queens I, II
N-Queens IThe 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 puz原创 2015-03-19 07:22:02 · 201 阅读 · 0 评论 -
Leetcode 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 define原创 2015-03-25 02:29:32 · 211 阅读 · 0 评论 -
Leetcode Wildcard matching
Implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matching should cover原创 2015-03-25 13:55:32 · 246 阅读 · 0 评论 -
Leetcode 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 an原创 2015-03-25 14:05:44 · 272 阅读 · 0 评论 -
Leetcode 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 class Solution { public原创 2015-03-25 14:08:13 · 175 阅读 · 0 评论 -
Leetcode Copy list with random pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.[code]/** * Definition for singly-link原创 2015-03-04 10:07:34 · 220 阅读 · 0 评论
分享