leetcode
文章平均质量分 73
zs709379096
这个作者很懒,什么都没留下…
展开
-
[LeetCode] Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum ton.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =原创 2017-06-04 10:28:56 · 167 阅读 · 0 评论 -
[LeetCode]Reconstruct Itinerary
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus,原创 2017-06-21 19:16:03 · 214 阅读 · 0 评论 -
[LeetCode] Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up t原创 2017-06-10 09:45:49 · 226 阅读 · 0 评论 -
[LeetCode]Subarray Sum Equals K
Total Accepted: 7118Total Submissions: 17265Difficulty: MediumContributors:love_FawnGiven an array of integers and an integer k, you need to find the total number of continuous subarrays whose原创 2017-06-11 10:42:29 · 183 阅读 · 0 评论 -
[LeetCode] ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2017-07-12 16:44:48 · 150 阅读 · 0 评论 -
[LeetCode] String to Integer (atoi)
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原创 2017-07-12 18:06:04 · 152 阅读 · 0 评论 -
[LeetCode] 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原创 2017-07-12 18:11:06 · 179 阅读 · 0 评论 -
[LeetCode] All O`one Data Structure
Implement a data structure supporting the following operations:Inc(Key) - Inserts a new key with value 1. Or increments an existing key by 1. Key is guaranteed to be a non-emptystring.Dec(Key)原创 2017-07-03 18:32:55 · 258 阅读 · 0 评论 -
[LeetCode] LFU Cache
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations:get and put.get(key) - Get the value (will always be positive) of the key原创 2017-07-02 20:06:10 · 236 阅读 · 0 评论 -
[LeetCode]LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:get and put.get(key) - Get the value (will always be positive) of the key if原创 2017-07-01 20:14:56 · 201 阅读 · 0 评论 -
[LeetCode]Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palind原创 2017-06-08 17:20:59 · 174 阅读 · 0 评论 -
[LeetCode] Target Sum
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find out h原创 2017-06-08 17:17:43 · 190 阅读 · 0 评论 -
[LeetCode] Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money原创 2017-06-04 10:56:23 · 384 阅读 · 0 评论 -
[LeetCode]Surrounded Regions
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,原创 2017-06-19 18:54:19 · 203 阅读 · 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原创 2017-06-19 19:25:18 · 185 阅读 · 0 评论 -
[LeetCode] Can I Win
In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.What if we change the game s原创 2017-06-08 10:39:46 · 318 阅读 · 0 评论 -
[LeetCode] Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5 y原创 2017-06-04 11:40:54 · 172 阅读 · 0 评论 -
[LeetCode] Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret原创 2017-06-04 12:04:30 · 145 阅读 · 0 评论 -
[LeetCode] Count The Repetitions
Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc", 3] ="abcabcabc".On the other hand, we define that string s1 can be obtained from string s2 if we ca原创 2017-06-08 12:52:33 · 322 阅读 · 0 评论 -
[LeetCode] Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we ha原创 2017-06-08 14:07:30 · 190 阅读 · 0 评论 -
[LeetCode] Predict the Winner
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a原创 2017-06-08 16:37:31 · 163 阅读 · 0 评论 -
[LeetCode] Insert Delete GetRandom O(1) - Duplicates allowed
Design a data structure that supports all following operations in average O(1) time.Note: Duplicate elements are allowed.insert(val): Inserts an item val to the collection.remove(val): Removes原创 2017-07-03 19:55:42 · 139 阅读 · 0 评论 -
[LeetCode] Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.代码如下:public class Solution { public int romanToInt(String s) { if(s.原创 2017-07-13 15:57:15 · 157 阅读 · 0 评论 -
Dijkstra 算法
Dijkstra 算法:import java.util.Arrays;public class Dijkstra { public static int[] dijkstra(int[][] graph,int start){ int[] dis=new int[graph.length]; boolean[] flag=new boolean[graph.length];原创 2017-06-25 14:43:55 · 165 阅读 · 0 评论 -
[LeetCode] Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be原创 2017-07-07 10:31:03 · 166 阅读 · 0 评论 -
[LeetCode] 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原创 2017-07-07 10:43:34 · 348 阅读 · 0 评论 -
[LeetCode] 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.字典树实现:public class Trie { Node root; /** Initi原创 2017-07-07 10:48:59 · 144 阅读 · 0 评论 -
[LeetCode] Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() a原创 2017-07-07 11:28:07 · 181 阅读 · 0 评论 -
[LeetCode]Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-07-07 13:49:05 · 178 阅读 · 0 评论 -
Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consis原创 2017-09-12 10:24:27 · 177 阅读 · 0 评论 -
Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answ原创 2017-10-07 02:00:43 · 198 阅读 · 0 评论 -
[LeetCode]Valid Parenthesis String
Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:Any left paren原创 2017-10-11 01:22:19 · 210 阅读 · 0 评论 -
Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar原创 2017-10-06 14:05:31 · 155 阅读 · 0 评论 -
[LeetCode] 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原创 2017-07-06 20:19:17 · 166 阅读 · 0 评论 -
[LeetCode] 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原创 2017-07-06 19:37:55 · 197 阅读 · 0 评论 -
[LeetCode]Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public String intToRoman(int num) { String[] str={"M","CM原创 2017-07-13 16:53:38 · 157 阅读 · 0 评论 -
[LeetCode] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0) return "";原创 2017-07-13 19:31:12 · 197 阅读 · 0 评论 -
[LeetCode] 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 "()", wh原创 2017-07-14 00:45:57 · 208 阅读 · 0 评论 -
[LeetCode] Insert Delete GetRandom O(1)
Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present.remove(val): Removes an item val from the s原创 2017-07-06 01:59:55 · 192 阅读 · 0 评论 -
[LeetCode] Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solution原创 2017-06-06 09:13:23 · 217 阅读 · 0 评论