
Leetcode
JasonComeOn
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
spring 拦截器
http://haohaoxuexi.iteye.com/blog/1750680 SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理。比如通过它来进行权限验证,或者是来判断用户是否登陆,或者是像12306 那样子判断当前时间是否是购票时间。 一、定义Interceptor实现类SpringMVC 中的Inte转载 2015-12-30 10:47:06 · 1864 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree Java LeetCode
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two原创 2015-07-31 11:06:52 · 293 阅读 · 0 评论 -
Power of Two LeetCode Java
Given an integer, write a function to determine if it is a power of two.一行解决战斗:return n > 0 && (n & (n - 1)) == 0;原创 2015-07-06 11:52:07 · 537 阅读 · 0 评论 -
Contains Duplicate III
本博文参考自:https://leetcode.com/discuss/38206/ac-o-n-solution-in-java-using-buckets-with-explanationGiven an array of integers, find out whether there are two distinct indices i and j in the array such tha翻译 2015-06-30 19:50:35 · 355 阅读 · 0 评论 -
The Skyline Problem Leetcode Java
public class Solution { class KeyPoint { public int key; public int height; public KeyPoint next = null; public KeyPoint(int key, int height) { this.key = k转载 2015-06-30 17:46:53 · 418 阅读 · 0 评论 -
Word Search II Leetcode Java
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizont原创 2015-06-29 17:06:47 · 547 阅读 · 0 评论 -
Majority Element 和 Majority Element II LeetCode Java
Majority Element Total Accepted: 44517 Total Submissions: 127008 My Submissions Question Solution Given an array of size n, find the majority element. The majority element is the element that appears原创 2015-06-29 15:45:33 · 466 阅读 · 0 评论 -
Course Schedule I II LeetCode Java
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 a pair:转载 2015-06-27 15:58:09 · 445 阅读 · 0 评论 -
Combination Sum III Leecode Java
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers within原创 2015-06-05 17:03:43 · 347 阅读 · 0 评论 -
House Robber II LeetCode Java
本博客参考自:https://leetcode.com/discuss/36544/simple-ac-solution-in-java-in-o-n-with-explanationNote: This is an extension of House Robber.After robbing those houses on that street, the thief has found him翻译 2015-06-24 16:10:35 · 357 阅读 · 0 评论 -
Shortest Palindrome Leetcode Java
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For example:G原创 2015-06-24 14:27:50 · 359 阅读 · 0 评论 -
Maximal Square Leetcode Java
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing all 1’s and return its area.For example, given the following matrix:1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Retu原创 2015-06-03 19:47:11 · 353 阅读 · 0 评论 -
Delete Node in a Linked List Java LeetCode
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t原创 2015-07-31 12:21:20 · 1198 阅读 · 0 评论 -
Missing Number Leetcode 268 Java
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 2.Note: Your algorithm should run in line原创 2015-09-01 15:23:40 · 424 阅读 · 0 评论 -
LeetCode:242 Valid Anagram Java
Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assume the s原创 2015-08-05 21:07:08 · 1886 阅读 · 0 评论 -
LeetCode 5 Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.找到一个字符串中最大的回文子字符串程序来自:https转载 2015-09-12 16:03:35 · 336 阅读 · 0 评论 -
LeetCode 1 Two sum Java
Given 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, where in转载 2015-07-06 15:46:00 · 255 阅读 · 0 评论 -
Leetcode 4 Median of Two Sorted Arrays Java
There are two sorted arrays nums1 and nums2 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)).这道题目看似比较简单,做起来才发现暗藏玄机。。。。这道题的一转载 2015-04-30 16:09:07 · 252 阅读 · 0 评论 -
LeetCode 279 PerfectSquares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, return原创 2015-09-11 12:24:23 · 351 阅读 · 0 评论 -
Leetcode 3 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “原创 2015-09-12 10:26:47 · 299 阅读 · 0 评论 -
Leetcode 2 Add Two Numbers Java
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-07-06 16:01:11 · 226 阅读 · 0 评论 -
LeetCode 274/275 H-Index Java
H-Index IGiven 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:原创 2015-09-11 11:14:28 · 611 阅读 · 0 评论 -
LeetCode 278: First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the原创 2015-09-10 11:23:51 · 469 阅读 · 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(n).For e原创 2015-08-06 19:56:37 · 224 阅读 · 0 评论 -
LeetCode 239 Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window mo原创 2015-08-06 19:16:22 · 424 阅读 · 0 评论 -
Ugly Number I 和 II LeetCode
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it in原创 2015-09-01 16:10:17 · 346 阅读 · 0 评论 -
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 letters a原创 2015-06-02 23:42:25 · 281 阅读 · 0 评论 -
Kth Largest Element in an Array LeetCode Java
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.Note:翻译 2015-06-23 15:58:27 · 290 阅读 · 0 评论 -
Count Complete Tree Nodes LeetCode Java
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and原创 2015-06-23 11:55:02 · 276 阅读 · 0 评论 -
Recover Binary Search Tree Leetcode Java
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note: A solution using O(n) space is pretty straight forward. Could you devise a const原创 2015-05-02 23:58:52 · 240 阅读 · 0 评论 -
Scramble String LeetCode JAVA
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 eat / \原创 2015-04-29 16:26:12 · 275 阅读 · 0 评论 -
Isomorphic Strings Leetcode JAVA
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 another chara原创 2015-04-29 12:39:21 · 451 阅读 · 0 评论 -
Count Primes Leetcode JAVA
Description:Count the number of prime numbers less than a non-negative number, n题意非常简单,给定一个非负数n,返回小于等于n 的素数的个数。看了题,so easy,直接造,第一版程序如下: public int countPrimes0(int n) { int rst=0; for原创 2015-04-29 11:06:08 · 314 阅读 · 0 评论 -
Leetcode Edit Distance Java
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:a) In原创 2015-04-15 10:16:31 · 308 阅读 · 0 评论 -
Leetcode:Substring with Concatenation of All Words【JAVA】
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any原创 2015-04-13 11:02:25 · 271 阅读 · 0 评论 -
Candy Java
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.原创 2015-04-11 18:44:43 · 201 阅读 · 0 评论 -
Palindrome Partitioning II Leetcode Java
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = “aab”, Return 1 since原创 2015-04-30 11:03:05 · 346 阅读 · 0 评论 -
Bitwise AND of Numbers Range JAVA
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4.Credits: Special thanks to翻译 2015-04-29 14:33:43 · 290 阅读 · 0 评论 -
Remove Linked List Elements Leetcode JAVA
Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5Credits: Special thanks to @mithmatt for a原创 2015-04-29 13:57:50 · 223 阅读 · 0 评论 -
Leetcode Distinct Subsequences Java
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of转载 2015-04-15 13:37:16 · 319 阅读 · 0 评论