原创 797. All Paths From Source to Target

題目 https://leetcode.com/problems/all-paths-from-source-to-target/ Given a directed, acyclic graph of N nodes. Find a

原创 976. Largest Perimeter Triangle

題目 鏈接:https://leetcode.com/problems/largest-perimeter-triangle/ Given an array A of positive lengths, return the larg

原创 SparseArray:解析與實現

介紹 Android提供了SparseArray,這也是一種KV形式的數據結構,提供了類似於Map的功能。但是實現方法卻和HashMap不一樣。它與Map相比,可以說是各有千秋。 優點 佔用內存空間小,沒有額外的Entry對象 沒有

原创 LeetCode.67. Add Binary

https://leetcode.com/problems/add-binary/ 分別從最後面開始取字符,一直往前取,如果其中一個長一個短,那麼短的那個取到的就是0,然後分別考慮 00 11 01 的情況,裏面分別對是否有進位進行處

原创 LeetCode.482. License Key Formatting

https://leetcode.com/problems/license-key-formatting/ class Solution { public String licenseKeyFormatting(String

原创 LeetCode.929. Unique Email Addresses

https://leetcode.com/problems/unique-email-addresses/ class Solution { public int numUniqueEmails(String[] emails

原创 LeetCode.155. Min Stack

https://leetcode.com/problems/min-stack/ 用一個棧來實現,有個巧妙的方法,就是遇到一個更小的或者與當前相等的值,就push兩次。這樣就相遇先保存了上一次的最小值,再保存了當前的數值。 pop的時

原创 LeetCode.139. Word Break

https://leetcode.com/problems/word-break/ 哈哈這道題我覺得還是有點難度的,沒想到寫完代碼直接過,還超過了99%。當時就脫口而出WTF!爽到 說說我的思路。 我們要判斷一堆詞是否可以組成字符串s

原创 LeetCode.5. Longest Palindromic Substring

https://leetcode.com/problems/longest-palindromic-substring/ 找到最長的迴文子串。 一種方法是從頭到尾遍歷一次,在每次迭代中,以當前字符爲中心,像兩側擴展判斷是否爲迴文。 然

原创 LeetCode.9. Palindrome Number

https://leetcode.com/problems/palindrome-number/ 從數字的末尾開始取數字,並構造與剩餘的原數字進行比較 class Solution { public boolean isPal

原创 LeetCode.146. LRU Cache

https://leetcode.com/problems/lru-cache/ 使用map加雙向鏈表的方式來存儲,get的時候,通過map獲取數據,put的時候,通過雙向鏈表的特性,可以在常量時間移動節點到頭部,刪除尾部節點。 cl

原创 LeetCode.283. Move Zeroes

https://leetcode.com/problems/move-zeroes/ 一開始想複雜了,還用雙指針 其實很簡單,先遍歷一遍,用一個自增的指針,指向下一個非0數擺放的位置。遍歷完了之後,非0的數都擺到前面了,解決後面全部改

原创 我的知識體系結構

計算機科學 排序算法 快速排序 歸併排序 堆排序 插入排序 選擇排序 桶排序 計算機中的數與數據 進制及其轉換 Java Java小細節:List可以add(null)嗎? HashMap 垃圾回收 WeakRefer

原创 WeakReference, SoftReference, ReferenceQueue學習與實驗

WeakReference, SoftReference Java中有四種引用類型,分別是Strong, Soft, Weak, Phantom Strong ref:強引用,被引用的對象在gc的時候不會被回收。 我們先來理解一下這句

原创 LeetCode.56. Merge Intervals

https://leetcode.com/problems/merge-intervals/ class Solution { public List<Interval> merge(List<Interval> interv