摘要:
真是被这道题气死了,总是弄不对 The problem says that we can make at most k changes to the string (any character can be replaced with any other character). So, let's 阅读全文
摘要:
Solution 1: Bit Manipulation: 这题真心有点难,get the max XOR bit by bit note that if A^B=C, then A^C=B, B^C=A Solution 2: Trie, (未研究) https://discuss.leetcod 阅读全文
摘要:
Time Complexity will be O(n) because the "start" and "end" points will only move from left to right once. Sliding Window: Use a count to denote the di 阅读全文
摘要:
这题考点在于需要设置两个visited数组 Two Queue and add all the Pacific border to one queue; Atlantic border to another queue. Keep a visited matrix for each queue. I 阅读全文
摘要:
Backpack problem: dp[i][j] means if the first i elements can sum up to value j dp[i][j] = dp[i-1][j] || (j>=nums[i-1] && dp[i-1][j-nums[i-1]]) the res 阅读全文
摘要:
The above image represents the elevation map [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] before the rain. After the rain, water are trapped between th 阅读全文
摘要:
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is =0 || j>=0 || carry!=0) { 8 int sum = 0; ... 阅读全文
摘要:
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not cons... 阅读全文
摘要:
Solution 1: Backtracking, but will TLE Better Solution: DP (refer to https://discuss.leetcode.com/topic/59903/very-easy-to-understand-java-solution-wi 阅读全文
摘要:
Graph, DFS (1) Build the map, the key is dividend, the value is also a map whose key is divisor and value is its parameter. For example, a / b = 2.0, 阅读全文
摘要:
Refer to: https://discuss.leetcode.com/topic/58334/a-couple-of-java-solutions-with-explanations/2 When to add 1 instead of minus 1, here is an example 阅读全文
摘要:
Analysis: Given a string s, find out all chars that are invalid (i.e., count < k). The longest substring must reside in one of the substrings divided 阅读全文
摘要:
Refer to https://discuss.leetcode.com/topic/56052/really-easy-understanding-solution-o-n-java and https://discuss.leetcode.com/topic/55923/o-n-solutio 阅读全文
摘要:
Basic Solution: DP, O(mn) time, O(m) space, m is the size of s, n is the size of t Greedy Solution: O(n) time, O(1) space Follow Up: The best solution 阅读全文
摘要:
refer to https://discuss.leetcode.com/topic/59293/java-easiest-solution-o-logn-with-explanation Time Complexity: O(log n) update and record head in ea 阅读全文
摘要:
Time Complexity: O(N) The depth of the directory/file is calculated by counting how many "\t"s are there.The time complexity is O(n) because each subs 阅读全文
摘要:
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may a... 阅读全文
摘要:
Solution 1: Solution 2: O(N) time, O(1) space The basic idea is to find the next number to add.Take 45 for example: if the current number is 45, the n 阅读全文
摘要:
Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 阅读全文