Golang 23 design patterns cheat sheets Creational patterns** Abstract FactoryTips： Use when got different modules have the same type of component with a different implementation. The factory method also got an abstracted interface for adapting different factory implementation.package

1249. Minimum Remove to Make Valid Parentheses Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that

binary search 162. Find Peak Element A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array

1295. Find Numbers with Even Number of Digits Given an array nums of integers, return how many of them contain an even number of digits. Example 1:Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits

substrings 647. Palindromic Substrings Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of

dp 10. Regular Expression Matching Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more

kth 402. Remove K Digits Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.Note: The length of num is less than 10002

Palindrome 680. Valid Palindrome II Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation:

Rectangle 85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"

trie 208. Implement Trie (Prefix Tree) Implement a trie with insert, search, and startsWith methods.Example: Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // returns true trie.search("app"); // returns false trie.startsWith("app"); // returns true trie.

trie 212. Word Search II Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are

stock 309. Best Time to Buy and Sell Stock with Cooldown Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many

stock 714. Best Time to Buy and Sell Stock with Transaction Fee Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You

stock 188. Best Time to Buy and Sell Stock IV Say you have an array for which the i-th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most

stock 123. Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most

stock 122. Best Time to Buy and Sell Stock II Say you have an array prices for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as

stock 121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e.

binary search First Bad Version You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on

binary tree Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree Given a binary tree where each path going from the root to any leaf form a valid sequence, check if a given string is a valid sequence in such binary tree. We get

linked List First Unique Number You have a queue of integers, you need to retrieve the first unique integer in the queue.Implement the FirstUnique class:FirstUnique(int[] nums) Initializes the object with the numbers in the queue.

dp Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.Example: Input: 1 0 1 0 0 1 0 1 1 1

greedy 55. Jump Game Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you

linked List 146. LRU Cache Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the

bit-manipulation 389. Find the Difference Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the

bit-manipulation 201. Bitwise AND of Numbers Range Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.Example 1: Input: [5,7] Output: 4 Example 2: