08 2016 档案
摘要:https://leetcode.com/problems/perfect-rectangle/ // https://discuss.leetcode.com/topic/55944/o-n-log-n-sweep-line-solution public class Solution { public class Column implements Comparabl...
阅读全文
摘要:https://leetcode.com/problems/find-the-difference/ public class Solution { public char findTheDifference(String s, String t) { char[] sch = s.toCharArray(); char[] tch = t.toChar...
阅读全文
摘要:https://leetcode.com/problems/longest-absolute-file-path/ public class Solution { public int lengthLongestPath(String input) { Stack stk = new Stack(); int left = 0; int ...
阅读全文
摘要:https://leetcode.com/problems/first-unique-character-in-a-string/ public class Solution { public int firstUniqChar(String s) { int[] index = new int[26]; for (int i=0; i 0) { ...
阅读全文
摘要:https://leetcode.com/problems/lexicographical-numbers/ public class Solution { public List lexicalOrder(int n) { List ret = new ArrayList(); int cur = 1; ret.add(cur); ...
阅读全文
摘要:https://leetcode.com/problems/mini-parser/ /** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * public i...
阅读全文
摘要:https://leetcode.com/problems/shuffle-an-array/ public class Solution { int [] origNums; int [] shufNums; java.util.Random rd; public Solution(int[] nums) { origNums = nums...
阅读全文
摘要:https://leetcode.com/problems/ransom-note/ public class Solution { public boolean canConstruct(String ransomNote, String magazine) { char[] chRan = ransomNote.toCharArray(); char...
阅读全文
摘要:https://leetcode.com/problems/linked-list-random-node/ // Using Reservoir sampling algorithm // https://discuss.leetcode.com/topic/53812/using-reservoir-sampling-o-1-space-o-n-time-complexity-c/2 /...
阅读全文
摘要:https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/ public class RandomizedCollection { ArrayList nums; HashMap> locs; java.util.Random rand; /** Initialize...
阅读全文
摘要:<!--?xml version="1.0" encoding="UTF-8" standalone="no"?--> http://www.cnblogs.com/lovebread/archive/2009/11/24/1609936.html
阅读全文
摘要:// 参考了下面一些讨论的解法 // https://discuss.leetcode.com/topic/53235/java-with-hashtable-arraylist/2 class RandomizedSet { vector vec; unordered_map umap; public: /** Initialize your data structu...
阅读全文
摘要://有很多讨论,比如 // https://discuss.leetcode.com/topic/52865/my-solution-using-binary-search-in-c // https://discuss.leetcode.com/topic/52912/binary-search-heap-and-sorting-comparison-with-concise-code-and...
阅读全文
摘要:#include class Solution { unordered_map dp_map; vector vec; int func(int target) { if (dp_map.find(target) != dp_map.end()) { return dp_map[target]; ...
阅读全文
摘要:// 参考了:https://discuss.leetcode.com/topic/51893/two-solutions-one-is-dp-the-other-is-greedy-8-lines // 另有:https://discuss.leetcode.com/topic/51946/very-simple-java-solution-with-detail-explanation c...
阅读全文