原创 2.1.9 3Sum Closest

Link: https://oj.leetcode.com/problems/3sum-closest/ 這題和3Sum 幾乎一樣。下面是我一次寫的代碼,基本正確。 Time: O(n^2), Space: O(1) public cla

原创 2.1.3 Search in Rotated Sorted Array

Link: https://oj.leetcode.com/problems/search-in-rotated-sorted-array/ Time: O(logn), Space: O(1) My code: public clas

原创 2.1.12 Next Permutation

Link: https://oj.leetcode.com/problems/next-permutation/ Implement next permutation, which rearranges numbers into the

原创 2.1.7 Two Sum

Link: https://oj.leetcode.com/problems/two-sum/ Given an array of integers, find two numbers such that they add up to

原创 2.1.4 Search in Rotated Sorted Array II

Link: https://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/ Follow up for "Search in Rotated Sorted Arra

原创 2.1.13 Permutation Sequence

Link: https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] contains a total of n! unique permut

原创 Kth Largest Element in an Array

Solution 1: 自己寫的 O(nk), Runtime: 126 ms, beats 1.73% submissions. public class Solution { public int findKthLarges

原创 DFS 總結

Subsets I, II //doneCombinations//donePermutations I, II (可先不做)//doneCombination Sum I, II (可先不做) Generate Parentheses

原创 2.2.6 Rotate List

Link: https://oj.leetcode.com/problems/rotate-list/ Given a list, rotate the list to the right by k places, where k is

原创 2.2.7 Remove Nth Node From End of List

Link: https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ Given a linked list, remove the nth node from

原创 2.2.3 Partition List

Link: https://oj.leetcode.com/problems/partition-list/ 這是CC150原題,我的思路正確,但代碼有問題。再做。 Time: O(n), Space: O(1) 我的代碼: public

原创 2.2.5 Remove Duplicates from Sorted List II

Link: https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ Given a sorted linked li

原创 Majority Element

五種方法: Hash table-Runtime: O(n), Space: O(n) Maintain a hash table of the counts of each element, then find the most co

原创 2.1.24 Single Number II

Link: https://oj.leetcode.com/problems/single-number-ii/ Given an array of integers, every element appears three times

原创 CLRS 學習計劃

I (1-5):     1, 2, 3, 4 (Master Theorem) //8.22 - 8.25 II (6-9):     6, 7, 8, 9  //8.26-8.31 III (10-14): 10 (Basic),