![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 92
sundawei2016
这个作者很懒,什么都没留下…
展开
-
Leetcode 460. 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-06-25 21:51:44 · 198 阅读 · 0 评论 -
Leetcode 72. Edit Distance
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:原创 2017-07-17 16:28:30 · 134 阅读 · 0 评论 -
Course Schedule I && II 总结
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原创 2017-07-17 21:36:30 · 219 阅读 · 0 评论 -
Leetcode 368. 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-07-30 15:57:59 · 164 阅读 · 0 评论 -
Leetcode 621. Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could b原创 2017-07-21 14:37:34 · 345 阅读 · 0 评论 -
Leetcode 464. 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-07-30 22:28:23 · 210 阅读 · 0 评论 -
Leetcode 133. Clone Graph
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 each原创 2017-07-18 15:05:26 · 171 阅读 · 0 评论 -
Leetcode 547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, the原创 2017-07-18 17:22:36 · 331 阅读 · 0 评论 -
Leetcode 305. Number of Islands II
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) into a land. Given a list of positions to opera原创 2017-07-18 18:23:25 · 361 阅读 · 0 评论 -
Leetcode 159. Longest Substring with At Most Two Distinct Characters
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3. public in原创 2017-07-17 01:30:20 · 593 阅读 · 0 评论 -
Leetcode 76. Minimum Window Substring
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原创 2017-07-16 23:25:19 · 365 阅读 · 0 评论 -
Leetcode Maze 总结
There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, i原创 2017-07-06 16:14:26 · 452 阅读 · 0 评论 -
Search a 2D Matrix
74. Search a 2D MatrixWrite 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 rig原创 2017-06-26 00:06:31 · 118 阅读 · 0 评论 -
Leetcode Palindrome Permutation I & II
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return[ ["aa","原创 2017-07-14 01:22:55 · 283 阅读 · 0 评论 -
Leetcode 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dict原创 2017-07-14 11:36:20 · 142 阅读 · 0 评论 -
Leetcode 320. Generalized Abbreviation
Write a function to generate the generalized abbreviations of a word. public List generateAbbreviations(String word) { List res = new ArrayList<>(); StringBuilder tmp = new String原创 2017-07-05 19:02:57 · 254 阅读 · 0 评论 -
Leetcode 556. Next Greater Element III
Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer nand is greater in value than n. If no such positive 32-bit原创 2017-07-14 18:58:08 · 531 阅读 · 0 评论 -
Leetcode 272. Closest Binary Search Tree Value II
Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.Note:Given target value is a floating point.You may assume k is always valid,原创 2017-07-05 22:02:35 · 204 阅读 · 0 评论 -
Leetcode 361. Bomb Enemy
Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return the maximum enemies you can kill using one bomb.The bomb kills all the enemies in the same row原创 2017-07-14 22:58:34 · 240 阅读 · 0 评论 -
Leetcode 416. Partition Equal Subset Sum
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array原创 2017-07-15 21:20:37 · 117 阅读 · 0 评论 -
Leetcode 115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (原创 2017-07-18 22:14:15 · 186 阅读 · 0 评论 -
Leetcode 261. Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n = 5 an原创 2017-07-19 00:05:53 · 772 阅读 · 0 评论 -
word break/pattern/ladder
139. Word BreakGiven a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dic原创 2017-08-05 18:36:24 · 365 阅读 · 0 评论 -
Leetcode 126. Word Ladder II
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEac原创 2017-08-05 18:44:34 · 227 阅读 · 0 评论 -
Leetcode 658. Find K Closest Elements
Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If there is a tie, the smaller elements are always p原创 2017-08-14 22:45:16 · 873 阅读 · 0 评论 -
Leetcode 130. 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-08-15 16:20:29 · 161 阅读 · 0 评论 -
Leetcode 269. Alien Dictionary
There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of non-empty words from the dictionary, where words are sorted le原创 2017-08-16 00:59:20 · 400 阅读 · 0 评论 -
recursive and iterative ways to reverse a LinkedList
public ListNode reverseList(ListNode head) { return helper(head, null); } private ListNode helper(ListNode head, ListNode newHead) { if (head == null) return newHead; L原创 2017-08-29 04:58:02 · 286 阅读 · 0 评论 -
Leetcode Combination
Combination Sum 1Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated原创 2017-08-29 12:27:40 · 504 阅读 · 0 评论 -
Leetcode 230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.给一个BST, 找到第 K 小的数方法原创 2017-10-01 08:53:12 · 163 阅读 · 0 评论 -
Leetcode 315. Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Example原创 2017-07-26 18:06:43 · 338 阅读 · 0 评论 -
Leetcode 310. Minimum Height Trees
For 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 minimum height are called mini原创 2017-07-26 16:05:12 · 157 阅读 · 0 评论 -
Leetcode 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther原创 2017-07-25 22:00:25 · 188 阅读 · 0 评论 -
Leetcode 149. Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.思路是:用两个循环去查看所有情况same 表示两个点完全重合sameX 表示两个点有相同的x坐标public int maxPoints(Point[] poin原创 2017-08-01 01:23:26 · 168 阅读 · 0 评论 -
Leetcode 282. Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or *between the digits so they evaluate to the target value.Exam原创 2017-07-19 20:04:31 · 160 阅读 · 0 评论 -
Leetcode Basic Calculator I && II
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em原创 2017-07-20 01:04:04 · 157 阅读 · 0 评论 -
Leetcode 410. Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m sub原创 2017-08-01 15:14:37 · 166 阅读 · 0 评论 -
Leetcode 174. Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p原创 2017-08-16 16:57:47 · 136 阅读 · 0 评论 -
Read N Characters Given Read4
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the原创 2017-08-16 19:55:34 · 222 阅读 · 0 评论 -
Leetcode 395. Longest Substring with At Least K Repeating Characters
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Example 1:Input:s = "aaabb", k =原创 2017-08-02 22:35:20 · 158 阅读 · 0 评论