leetcode - summer2020

2020/06/07 

[001] 24. Swap Nodes in Pairs (LinkedList - Java)

  - Description: https://leetcode.com/problems/swap-nodes-in-pairs/

  - Submission Time + Difficulty: 1, 5 (1 ~ 10)

  - dummy head, border case

 

[002] 61. Rotate List (LinkedList - Java)

  - Description: https://leetcode.com/problems/rotate-list/

  - Submission Time + Difficulty: 2, 5 (1 ~ 10)

  - switch direction since the list is only single direction.

 

[003] 205. Isomorphic Strings (HashMap - Java)

  - Description: https://leetcode.com/problems/isomorphic-strings/

  - Submission Time + Difficulty: 3, 4 (1 ~ 10)

  - return false when two different characters in string s match to the same character in string t.

  - syntax: h.containsKey(o), h.containsValue(o), h.put(key, value), h.get(key)

       Character.toString(c); s.charAt(index) // String <=> char

 

[004] 771. Jewels and Stones (HashMap - Java)

  - Description: https://leetcode.com/problems/jewels-and-stones/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

 

[005] 202. Happy Number (HashSet - Java)

  - Description: https://leetcode.com/problems/happy-number/

  - Submission Time + Difficulty: 1, 4 (1 ~ 10)

  - set ~ general interface to a set-like collection // hashset ~ a specific implementation of the set interface

 

 

2020/06/08 

[006] 692. Top K Frequent Words (vector, custom sort - C++)

  - Description: https://leetcode.com/problems/top-k-frequent-words/

  - Submission Time + Difficulty: 1, 6 (1 ~ 10)

  - use a map to match each string with its frequency in the string array. Save (int, string) into an array with element type pair<int, string> Sort it in decreasing order of int and increasing order of string

  - * cmp() can't be static, so it should be put out of the solution class.

 

[007] 373. Find K Pairs with Smallest Sums (heap - C++)

  - Description: https://leetcode.com/problems/find-k-pairs-with-smallest-sums/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - use priority_queue or custom sort

 

 

2020/06/12 

[008] 451. Sort Characters By Frequency (HashMap - Java)

  - Description: https://leetcode.com/problems/sort-characters-by-frequency/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - brute force

 

[009] 739. Daily Temperatures (Stack - Java)

  - Description: https://leetcode.com/problems/daily-temperatures/

  - Submission Time + Difficulty: 1, 4 (1 ~ 10)

  - search from the beginning to the end. Use a stack to maintain all indices which we don't find answers and store them in the increasing order.

 

[010] 21. Merge Two Sorted Lists (LinkedList - Java)

  - Description: https://leetcode.com/problems/merge-two-sorted-lists/

  - Submission Time + Difficulty: 2, 3 (1 ~ 10)

  - Be careful that the problem wants us to "merge two sorted linked lists", not two linked lists with random order.

 

[011] 445. Add Two Numbers II (LinkedList - Java)

  - Description: https://leetcode.com/problems/add-two-numbers-ii/

  - Submission Time + Difficulty: 2, 3 (1 ~ 10)

  - Not only should we select the longer length as the size of ans array, to avoid size extended, we should also initialize a1 and a2 array using the longer length.

 

 

2020/06/13 

[012] 226. Invert Binary Tree (BinaryTree - Java)

  - Description: https://leetcode.com/problems/invert-binary-tree/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

  - Simple recursion

 

[013] 101. Symmetric Tree (BinaryTree, Queue - Java)

  - Description: https://leetcode.com/problems/symmetric-tree/

  - Submission Time + Difficulty: 3, 4 (1 ~ 10)

  - BFS (queue). Should care about when root is null.

  - Initialize a queue using Java: Queue<TreeNode> q = new LinkedList<>();

 

[014] 554. Brick Wall (HashMap - Java)   video06/15

  - Description: https://leetcode.com/problems/brick-wall/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - prefix summation

 

 

2020/06/15 

[015] 138. Copy List with Random Pointer (LinkedList - Java)  video06/16

  - Description: https://leetcode.com/problems/copy-list-with-random-pointer/

  - Submission Time + Difficulty: 1, 7 (1 ~ 10)

  - First, to hard copy the next pointer, attend a node with the same value after each node. Second, update the random pointer. Then, delete the original node.

 

[016] 142. Linked List Cycle II (LinkedList, HashSet - Java)

  - Description: https://leetcode.com/problems/brick-wall/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - find the first node which already appears in the set where all previous nodes are saved. Large memory usage.

 

[017] 143. Reorder List (LinkedList - Java)

  - Description: https://leetcode.com/problems/reorder-list/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - custom class (e.g. ListNode) could be initialized as "ListNode[] lists = new ListNode[len]"

 

[018] 82. Remove Duplicates from Sorted List II (LinkedList, HashMap - Java)

  - Description: https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - Be careful that we need to delete all nodes with duplicate numbers, not to leave all numbers be unique. So, we should preprocess nodes' numbers and then delete the proper nodes.

 

[019] 23. Merge k Sorted List (LinkedList - Java)

  - Description: https://leetcode.com/problems/merge-k-sorted-lists/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - similar to merge 2 sorted lists.

 

 

2020/06/16 

[020] 110. Balanced Binary Tree (Binary Tree - Java)

  - Description: https://leetcode.com/problems/balanced-binary-tree/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - calculate each node's height by recursion

 

[021] 98. Validate Binary Search Tree (Binary Tree - Java)

  - Description: https://leetcode.com/problems/validate-binary-search-tree/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - check infix order traversal

 

[022] 230. Kth Smallest Element in a BST (Binary Tree - Java)

  - Description: https://leetcode.com/problems/validate-binary-search-tree/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - calculate each node's height by recursion

 

[023] 232. Implement Queue using Stacks (Queue, ArrayList - Java)

  - Description: https://leetcode.com/problems/implement-queue-using-stacks/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

 

[024] 946. Validate Stack Sequences (Stack, ArrayList - Java)

  - Description: https://leetcode.com/problems/validate-stack-sequences/

  - Submission Time + Difficulty: 2, 3 (1 ~ 10)

  - it is possible to finish iterating through the popped[] before pushed[] ends.

 

[025] 907. Sum of Subarray Minimums (Stack - C++)

  - Description: https://leetcode.com/problems/sum-of-subarray-minimums/

  - Submission Time + Difficulty: 2, 5 (1 ~ 10)

  - brute force is ok since A.length <= 3*104, which indicates O(n^2) can work.

  - a O(n) solution using stack: iterate through A while maintaining each value together with the times as minimum (stack<pair<int, int> > s, where s.first = val, s.second = # as min). For each index i, we just add the sum of minimums of intervals which ends at i.

 

 

2020/06/17 

[026] 84. Largest Rectangle in Histogram (Stack - Java)   video06/17

  - Description: https://leetcode.com/problems/largest-rectangle-in-histogram/

  - Submission Time + Difficulty: 1, 7 (1 ~ 10)

  - O(n) w/ stack: the output should be certain width times certain height, where the height would be always equal to certain bar height in the histogram. So, we can iterate through all heights in order while exploring the maximum width. To do with, maintain a stack whose element type is int[] (0th stores the index and 1th stores the height, meaning that we can draw a rectangle using the height from index to the current_index). For each height, if it is larger than the height of top element in the stack, we just push the current index and the current height into the stack. Otherwise, pop elements until we encounter the element whose height is smaller than the current height.

 

[027] 112. Path Sum (Binary Tree - Java)

  - Description: https://leetcode.com/problems/path-sum/

  - Submission Time + Difficulty: 2, 3 (1 ~ 10)

  - special case: when root is null, should return false

 

[028] 785. Is Graph Bipartite? (dsu/bfs - Java)

  - Description: https://leetcode.com/problems/is-graph-bipartite/

  - Submission Time + Difficulty: 1, 6 (1 ~ 10)

  - dsu: for each node i in graph, define two corresponding nodes in dsu: i * 2 (i is in group 1), i * 2 + 1 (i is in group 2). For each edge x, y, we connect (x * 2, y * 2 + 1) and (x * 2, y * 2 + 1), meaning that either x in group1 y in group2 OR x in group2 y in group1. Check if i * 2 and i * 2 + 1 are in same dsu group. If there exists such i, return false.

  - bfs: queue to maintain all nodes in same group.

 

 

2020/06/18 

[029] 310. Minimum Height Trees (queue - C++)

  - Description: https://leetcode.com/problems/minimum-height-trees/

  - Submission Time + Difficulty: 1, 7 (1 ~ 10)

  - MHTs should be the middle node(s) in the longest path of the graph. Since the number of nodes in the graph is either odd or even, there should always be one or two MHTs. To find the longest path, delete all leaves and all corresponding edges for each round.

 

[030] 310. Evaluate Division (Connectivity - C++)

  - Description: https://leetcode.com/problems/evaluate-division/

  - Submission Time + Difficulty: 1, 5 (1 ~ 10)

  - Construct a directed graph. For each equation, x / y = v, add an edge from x to y with value v and an edge from y to x with value (1 / v).

 

 

2020/06/19 

[031] 236. Lowest Common Ancestor of a Binary Tree (LCA - Java)

  - Description: https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/

  - Submission Time + Difficulty: 1, 5 (1 ~ 10)

  - recursion from the root. If the current root share the same value with either p or q, return root, else continue explore root.left and root.right.

 

[032] 35. Search Insert Position (Array - Java)

  - Description: https://leetcode.com/problems/search-insert-position/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

 

[033] 383. Ransom Note (Array - Java)

  - Description: https://leetcode.com/problems/search-insert-position/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - Preprocess the times each character appears in the string magazine.

 

[034] 383. Toeplitz Matrix (2-dim array - Java)

  - Description: https://leetcode.com/problems/toeplitz-matrix/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

 

[035] 394. Decode String (Stack - Java)

  - Description: https://leetcode.com/problems/decode-string/

  - Submission Time + Difficulty: 1, 4 (1 ~ 10)

  - Store positions of '['. Extract repeated times and expand the original string whenever we encounter a ']'.

 

[036] 74. Search a 2D Matrix (2-dim array - Java)

  - Description: https://leetcode.com/problems/search-a-2d-matrix/

  - Submission Time + Difficulty: 2, 3 (1 ~ 10)

  - special case: matrix = []. We need to check whether the length and width of the matrix is 0.

 

 

2020/06/20 

[037] Longest Substring Without Repeating Characters (尺取法 - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3008/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - search in order. delete all characters in the hashset when we find a repeating character.

 

[038] String to Integer (atoi) (brute force - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3009/

  - Submission Time + Difficulty: 8, 5 (1 ~ 10)

  - Special cases: 1. str only made up of ' '; 2. str = '   +'; 3. str has only one character; 4. value exceeded

 

[039] Roman to Integer (brute force - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3010/

  - Submission Time + Difficulty: 1, 4 (1 ~ 10)

  - Check whether two consecutive digits can form valid integer before transforming only the current roman digit.

 

[040] 3Sum (sorting, searching - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/283/

  - Submission Time + Difficulty: 1, 5 (1 ~ 10)

  - First, sort the array in increasing order. Select a number x (since the sum of three numbers is 0, we only need to check non-positive number) and check whether two numbers in the remaining array has the sum -x.

 

[041] Remove Duplicates from Sorted Array (brute force - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3011/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - since the array has been already sorted, we check each element in order.

 

 

2020/06/21 

[042] Next Permutation (searching - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3012/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - check from the last element to the front and find the first element that is bigger than the element behind it.

 

[043] Multiple Strings (math - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3013/

  - Submission Time + Difficulty: 2, 4 (1 ~ 10)

  - high-precision multiplication. When we determine the length of the final result, be careful that we should check from (len1 + len2 - 2) index until we find the index with non-zero value instead of searching for the first index with value 0. counterexample: 6, 501.

 

[044] Find the Duplicate Number (Graph - Java)

  - Description: https://leetcode.com/problems/find-the-duplicate-number/

  - Submission Time + Difficulty: 1, 7 (1 ~ 10)

  - the difficult point of the problem is that the array is only readable (we can't modify its elements) and we are given only O(1) extra space and need to solve it within O(n ^ 2) time complexity. But it also provides some special conditions: there are (n + 1) numbers covering 1 ~ n with the rule that exact one number appears twice and all others appear once. A tricky solution is to focus on our special condition and transform the problem into finding a loop in a graph. For each number v out of (n + 1) numbers in index u (indices are from 0 to n), consider it as an edge from u to v.  Due to the condition, every node is reachable and there is one and only one loop.

 

 

2020/06/22 

[045] Spiral Matrix (2-dim array - Java)

  - Description: https://leetcode.com/problems/spiral-matrix/

  - Submission Time + Difficulty: 2, 4 (1 ~ 10)

  - special case: []. we should output [] instead of null.

 

[046] 4Sum (2-dim array - Java)

  - Description: https://leetcode.com/problems/4sum/

  - Submission Time + Difficulty: 3, 2 (1 ~ 10)

  - make sure to avoid duplicate solutions.

 

[047] Trapping Rain Water II (priority_queue - C++)

  - Description: https://leetcode.com/problems/trapping-rain-water-ii/

  - Submission Time + Difficulty: 1, 6 (1 ~ 10)

  - use priority_queue with element type (height, (row index, column index)) to update the volumn of water each block can hold. We first push all corner and edge blocks. Each time we pop the element in the priority_queue with minimal height while updating the total water storage capacity and pushing all its neighboring blocks which haven't been visited.

 

 

2020/06/23 

[048] Letter Combinations of A Phone Number (HashMap - Java)

  - Description: https://leetcode.com/problems/letter-combinations-of-a-phone-number/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - Easy to inquire the corresponding characters with each number if we use hashmap.

 

[049] Merge Intervals (Sorting - C++)

  - Description: https://leetcode.com/problems/merge-intervals/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - Store each interval with the datatype pair<int, int>. Find the final intervals in increasing order. Define the current interval by [cur_l, cur_r]. For each node [l, r], if cur_r < l, add [cur_l, cur_r] to the final vector<vector<int> >. Otherwise [cur_l, cur_r] := [cur_l, max(cur_r, r)].

 

[050] House Robber III (DP, Graph - Java)

  - Description: https://leetcode.com/problems/house-robber-iii/

  - Submission Time + Difficulty: 2, 4 (1 ~ 10)

  - For each node, consider two cases: choose or not choose this node. Then DP.

 

[051] Minimum Depth of Binary Tree (BFS - Java)

  - Description: https://leetcode.com/problems/minimum-depth-of-binary-tree/

  - Submission Time + Difficulty: 4, 4 (1 ~ 10)

  - If the node is a leaf, return 1. If the node has only left or right children, return the height of its only children. Otherwise, return the smaller height.

 

[052] Minimum Depth of Binary Tree (BFS - Java)

  - Description: https://leetcode.com/problems/minimum-depth-of-binary-tree/

  - Submission Time + Difficulty: 4, 4 (1 ~ 10)

  - If the node is a leaf, return 1. If the node has only left or right children, return the height of its only children. Otherwise, return the smaller height.

 

[053] Binary Tree Pruning (Graph, Recursion - Java)

  - Description: https://leetcode.com/problems/binary-tree-pruning/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - For each node, check its left subtrees, right subtrees have zero(s) and the node itself have zero(s).

 

 

2020/06/24 

[054] Best Time to Buy and Sell Stock II (brute force - Java)

  - Description: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - sorting both arrays in increasing order and do comparisons.

 

[055] Non-overlapping intervals (dp - C++)

  - Description: https://leetcode.com/problems/non-overlapping-intervals/

  - Submission Time + Difficulty: 2, 4 (1 ~ 10)

  - sorting the intervals such that ending point is increasing order. Then do DP.

 

[056] Non-overlapping intervals (brute force - Java)

  - Description: https://leetcode.com/problems/maximum-product-of-three-numbers/

  - Submission Time + Difficulty: 4, 4 (1 ~ 10)

  - 4 cases: 3 pos, 1 pos 2 neg, 0, 3 neg.

 

 

2020/06/25 

[057] Group Anagrams (unordered map, vector - C++)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3014/

  - Submission Time + Difficulty: 1, 4 (1 ~ 10)

  - we can use sort(s.begin(), s.end()); to sort a string s in increasing order. Syntax!

 

[058] Add Binary (math - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/263/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - same as it in binary.

 

[059] Minimum Window Substring (尺取法 - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/285/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - similar to [037].

 

[060] Merged Sorted Array (sorting - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/309/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - store the final answer from the end of the array to the beginning.

 

 

2020/06/27 

[061] Binary Tree Level Order Traversal II (queue - Java)

  - Description: https://leetcode.com/problems/binary-tree-level-order-traversal-ii/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - use a queue to store nodes at each level.

 

[062] Flatten Binary Tree to Linked List (recursion - Java)

  - Description: https://leetcode.com/problems/flatten-binary-tree-to-linked-list/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - for each node, after updating its left and right node (if any), we link its left subtree at the bottom of its right subtree.

 

[063] Find Duplicate Subtrees (recursion - Java)

  - Description: https://leetcode.com/problems/find-duplicate-subtrees/

  - Submission Time + Difficulty: 2, 5 (1 ~ 10)

  - since it is possible for true trees to share the same traversal even if they have different shapes, we need to care about the null node. So we encode the tree while encoding all its null node. Use a hashset to check whether a subtree has been duplicated.

 

 

2020/06/28 

[064] Valid Palindrome (brute force - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/288/

  - Submission Time + Difficulty: 2, 2 (1 ~ 10)

  - Read the description carefully! We should remain alphanumeric characters, not just letters.

 

[065] Read N Characters Given Read4 (brute force - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/268/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - Make sure how read4(buf) works. buf is an array which would be updated when read4 function is called.

 

[066] Read N Characters Given Read4 II - Call multiple times (brute force - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/269/

  - Submission Time + Difficulty: 2, 4 (1 ~ 10)

  - create pre[] as instance variable to store the remaining characters from the latest read4 operation.

 

[067] One Edit Distance (classification - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3015/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - notice that we should return false when two strings are the same since they are already identical to each other, i.e. zero edit distance, instead of one edit distance. The differences of length between two string should either 0 or 1 (-1).

 

 

2020/07/03 

[068] Product of Array Except Self (math - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3016/

  - Submission Time + Difficulty: 2, 2 (1 ~ 10)

  - Be careful when there are fewer than 2 elements in the array. Do multiplication once forward and once backward.

 

[069] Integer to English Words (brute force, hashmap - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/273/

  - Submission Time + Difficulty: 3, 5 (1 ~ 10)

  - use a hashmap to pair each segmented number with its corresponding name. Separate the given number from the last digit to the front three by three, decode the name for each segment and add "billion", "million", "thousand" behind. Be careful when 000 occurred where we ignore this segment (can't add "billion" etc behind). Also care about * hundreds.

 

[070] Move Zeroes (brute force, hashmap - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/262/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

  - same as 'remove duplicated elements'.

 

[071] Longest Substring with At Most K Distinct Characters (尺取法 - Java)

  - Description: https://leetcode.com/explore/interview/card/facebook/5/array-and-strings/3017/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - use l and r pointer to track the section and move forward l if we can't move forward r. Do it until r is out of bound.

 

 

2020/07/11 

[072] Set Matrix Zeroes (brute force - Java)

  - Description: https://leetcode.com/problems/set-matrix-zeroes/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

 

[073] Climbing Stairs (dp - JavaScript)

  - Description: https://leetcode.com/problems/climbing-stairs/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - var dp = new Array(n);   // define dp as an array with length n

  - comparison operator: === (equal value and equal type), !==

 

[074] Best Time to Buy and Sell Stock (brute force - JavaScript)

  - Description: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

  - Submission Time + Difficulty: 1, 1 (1 ~ 10)

  - Math.max(a, b, c) / Math.min(a, b, c);   // return the largest/ smallest element among a, b, and c.

 

[075] Minimum Path Sum (dp - JavaScript)

  - Description: https://leetcode.com/problems/minimum-path-sum/

  - Submission Time + Difficulty: 1, 2 (1 ~ 10)

  - to define a 2-dim array with size (n, m): var dp = new Array(n); for (var i = 0; i < n; i++) dp[i] = new Array(m);

  - we can directly set `var dp = grid` here to create a 2-dim array with the same elements as the grid array.

 

[076] Decode Ways (dp - JavaScript)

  - Description: https://leetcode.com/problems/decode-ways/

  - Submission Time + Difficulty: 1, 3 (1 ~ 10)

  - s.charCodeAt(idx);   // returns the ASCII code of the string s at idx

  - encoding string is invalid when '0' or '0*' happens

 

 

2020/07/30  

[077] Letter Case Permutation (backtracking - Java)

  - Description: https://leetcode.com/problems/letter-case-permutation/

  - Submission Time + Difficulty: 3, 1 (1 ~ 10)

  - Since numbers are distinct, we can set different labels (1 ~ n) with different numbers and convert them back into corresponding numbers after permutation with labels.

 

[078] Permutations (backtracking - Java)

  - Description: https://leetcode.com/problems/permutations/

  - Submission Time + Difficulty: 2, 1 (1 ~ 10)

 

[079] Combinations (backtracking - Java)

  - Description: https://leetcode.com/problems/combinations/

  - Submission Time + Difficulty: 2, 1 (1 ~ 10)

  - C(n, k)

 

[080] Combination Sum III (backtracking, recursion - Java)

  - Description: https://leetcode.com/problems/combination-sum-iii/

  - Submission Time + Difficulty: 5, 1 (1 ~ 10)

  - Since the order doesn't matter, the answer should be the number of 3-num set (a, b, c) where a<b<c and a+b+c=n. Try changing a, b while checking if c > n - a - b.

posted @ 2020-06-14 03:02  oeiuie  阅读(178)  评论(0)    收藏  举报