LeetCode
文章平均质量分 65
GigaCat
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode难度及面试频率
1Two Sum25arraysort setTwo Pointers2Add Two Numbers34linked listTwo Pointers转载 2014-03-03 09:03:22 · 698 阅读 · 0 评论 -
N-Queens II - LeetCode
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.本题主要是深度优先搜索:public class Solution { public int totalNQueens转载 2014-03-08 03:08:59 · 737 阅读 · 0 评论 -
Edit Distance - LeetCode
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:转载 2014-03-08 12:04:19 · 868 阅读 · 0 评论 -
Valid Palindrome - LeetCode
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2014-03-08 00:25:03 · 733 阅读 · 0 评论 -
Word Ladder - LeetCode
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediat转载 2014-03-07 16:11:54 · 1223 阅读 · 0 评论 -
Set Matrix Zeroes - LeetCode
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.AC代码,虽然有点复杂,但是一次通过了。public class Solution { public void setZeroes(int[][] matrix) {原创 2014-03-07 12:34:47 · 642 阅读 · 0 评论 -
Valid Parentheses - LeetCode
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-03-07 08:42:18 · 608 阅读 · 0 评论 -
Divide Two Integers - LeetCode
最初想到的简单暴力算法,超时了:public class Solution { public int divideHelper(int dividend, int divisor){ int result = 0; if(divisor == 0) return 0; else{ while(true){原创 2014-03-07 09:40:34 · 655 阅读 · 0 评论 -
Implement strStr() - LeetCode
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.这道题有很多需要注意的小点:(1)You have to check if a String == null before原创 2014-03-07 09:09:59 · 626 阅读 · 0 评论 -
leetcode之 Palindrome Partitioning I&II
http://blog.youkuaiyun.com/yutianzuijin/article/details/16850031转载 2014-02-21 13:40:29 · 913 阅读 · 0 评论 -
LeetCode - Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2014-02-13 14:23:04 · 641 阅读 · 0 评论 -
Restore IP Addresses - LeetCode
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原创 2014-03-08 11:37:06 · 768 阅读 · 0 评论 -
Max Points on a Line - LeetCode
找了很久还是没有找到巧解的方法。下面是暴力算法的博客链接:http://blog.youkuaiyun.com/worldwindjp/article/details/18882849转载 2014-02-20 12:15:18 · 630 阅读 · 0 评论 -
Container With Most Water - LeetCode
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-03-03 13:01:32 · 712 阅读 · 0 评论 -
Minimum Window Substring - LeetCode
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 "BAN转载 2014-02-24 04:44:09 · 853 阅读 · 1 评论 -
LeetCode - Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2014-02-11 06:41:21 · 654 阅读 · 0 评论 -
Insert Interval - LeetCode
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原创 2014-02-24 02:13:45 · 695 阅读 · 0 评论 -
Remove Nth Node From End of List - LeetCode
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-02-24 01:37:01 · 561 阅读 · 0 评论 -
Binary Tree Level Order Traversal II - LeetCode
随笔自用http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/原创 2014-02-22 14:30:50 · 566 阅读 · 0 评论 -
Binary Tree Postorder Traversal - LeetCode
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 solution is t原创 2014-01-19 08:08:33 · 724 阅读 · 0 评论 -
Single Number II - LeetCode
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2014-02-26 04:50:28 · 652 阅读 · 0 评论 -
LeetCode - Best Time to Buy and Sell Stock II
http://blog.youkuaiyun.com/fightforyourdream/article/details/14449133转载 2014-02-20 11:53:17 · 599 阅读 · 0 评论 -
String to Integer (atoi) - LeetCode
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca转载 2014-03-08 01:14:03 · 970 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node - LeetCode
http://blog.youkuaiyun.com/pickless/article/details/12027997转载 2014-02-26 04:08:22 · 644 阅读 · 0 评论 -
Gray Code
http://blog.youkuaiyun.com/sbitswc/article/details/20110655转载 2014-03-03 08:04:06 · 625 阅读 · 0 评论 -
Regular Expression Matching - LeetCode
利用递归的算法,观察*的位置,这道题非常好。public class Solution { public boolean isMatch(String s, String p) { // Start typing your Java solution below // DO NOT write main() function if(s.l转载 2014-03-03 12:13:37 · 584 阅读 · 0 评论 -
Clone Graph - LeetCode
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea转载 2014-02-24 09:19:47 · 850 阅读 · 1 评论 -
Subsets - LeetCode
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-02-24 12:17:00 · 614 阅读 · 0 评论 -
Reorder List - LeetCode
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to转载 2014-02-25 15:07:30 · 757 阅读 · 0 评论 -
Maximum Subarray - LeetCode
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原创 2014-02-26 05:07:19 · 739 阅读 · 0 评论 -
Search in Rotated Sorted Array - LeetCode
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-02-25 11:26:04 · 685 阅读 · 0 评论 -
Median of Two Sorted Arrays - LeetCode
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)).我写的太不简洁了,也没有优化,不过AC了:public cla原创 2014-03-03 08:49:12 · 646 阅读 · 0 评论 -
Longest Palindromic Substring - LeetCode
转自: http://blog.youkuaiyun.com/pickless/article/details/9040293选定一个位置,朝两边不断拓展,直到两边的字符不一样为止。这是最简单、最直观的想法,这个想法的时间复杂度是O(n2)。但是这不是最快速的算法,目前对于最长回文子串问题最快的解法的时间复杂度为O(n)。假设S=“gxgag转载 2014-03-03 10:48:04 · 493 阅读 · 0 评论 -
Merge Sorted Array - LeetCode
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 (size that is greater or equal to m + n) to hold additional elements from原创 2014-02-26 05:40:23 · 768 阅读 · 0 评论 -
Search for a Range - LeetCode
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-03-07 11:23:22 · 521 阅读 · 0 评论 -
Decode Ways - LeetCode
开始写了一个标准的DP,但是由于对于题意中的0没有弄清楚,所以没过:public class Solution {public int numDecodings(String s) { if(s == null) return 0; else if(s.length() == 0) return 0; int[] method = new int[s.le原创 2014-03-07 14:33:17 · 736 阅读 · 0 评论 -
Word Search - leetcode
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原创 2014-03-07 13:46:19 · 712 阅读 · 0 评论 -
Unique Paths - LeetCode
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-03-08 12:54:06 · 712 阅读 · 0 评论 -
Multiply Strings - LeetCode
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.首先,展示一个我看到的最吊,碉堡了的算法:import java.math原创 2014-03-07 11:59:42 · 655 阅读 · 0 评论 -
Validate Binary Search Tree - LeetCode
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th转载 2014-03-07 14:48:52 · 609 阅读 · 0 评论
分享