代码改变世界

随笔档案-2021年06月

[LeetCode] 211. Design Add and Search Words Data Structure_Medium tag: Trie, DFS

2021-06-30 01:11 by Johnson_强生仔仔, 27 阅读, 收藏, 编辑
摘要: Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class 阅读全文

[LeetCode] 642. Design Search Autocomplete System_Hard tag: Trie

2021-06-30 00:03 by Johnson_强生仔仔, 50 阅读, 收藏, 编辑
摘要: Design a search autocomplete system for a search engine. Users may input a sentence (at least one word and end with a special character '#'). You are 阅读全文

[LeetCode] 212. Word Search II_Hard tag: Trie, DFS

2021-06-29 20:06 by Johnson_强生仔仔, 39 阅读, 收藏, 编辑
摘要: Given an m x n board of characters and a list of strings words, return all words on the board. Each word must be constructed from letters of sequentia 阅读全文

[LeetCode] 208. Implement Trie (Prefix Tree)_Medium tag: Trie

2021-06-29 05:20 by Johnson_强生仔仔, 36 阅读, 收藏, 编辑
摘要: A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are va 阅读全文

[LeetCode] 703. Kth Largest Element in a Stream_Easy tag: Heap

2021-06-28 10:41 by Johnson_强生仔仔, 22 阅读, 收藏, 编辑
摘要: Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. 阅读全文

[LeetCode] 347. Top K Frequent Elements_Medium tag: Array, Heap, quickSort

2021-06-28 09:51 by Johnson_强生仔仔, 50 阅读, 收藏, 编辑
摘要: Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1 阅读全文

[LeetCode] 215. Kth Largest Element in an Array_Medium tag: sort, Heap, quickSort

2021-06-28 09:04 by Johnson_强生仔仔, 45 阅读, 收藏, 编辑
摘要: Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order 阅读全文

quickSort use two pointers to decrease Time into O(n * lgn ) or O(n)

2021-06-28 08:45 by Johnson_强生仔仔, 44 阅读, 收藏, 编辑
摘要: Quicksort, 选取pivot, 然后有两个指针, left = 0, right = n - 1, left 不停右移找到nums[left] > pivot, right 不停左移找到nums[right] <= pivot直到left >= right, 停止,那么这时候再recursi 阅读全文

[LeetCode] 560.Subarray Sum Equals K_Medium tag: Array, Subarray, prefix Sum

2021-06-18 20:36 by Johnson_强生仔仔, 33 阅读, 收藏, 编辑
摘要: Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k. Example 1: Input: nums = [1,1 阅读全文

Prefix Sum & Dictionary Time and Space O(n) for -- Find a number of continuous subarrays/submatrices/tree paths that sum to target

2021-06-18 20:31 by Johnson_强生仔仔, 47 阅读, 收藏, 编辑
摘要: Prefix sum, 参考这个solution, 讲解的很清楚。 . What is prefix sum Prefix sum is a sum of the current value with all previous elements starting from the beginning 阅读全文

Morris Traversal_ O(1) space to change binary tree to linked list

2021-06-18 19:04 by Johnson_强生仔仔, 48 阅读, 收藏, 编辑
摘要: 问题可以参考[LeetCode] 114. Flatten Binary Tree to Linked List_Medium tag: DFS, 这个Morris Traversal能够解决follow up,怎么样用 space O(1) 来去解决这个问题。参考这个题目的solution的app 阅读全文

[LeetCode] 1485. Clone Binary Tree With Random Pointer_ Medium tag: BFS, DFS

2021-06-16 09:21 by Johnson_强生仔仔, 86 阅读, 收藏, 编辑
摘要: A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a deep copy 阅读全文

[LeetCode] 系统刷题9_Backtracking

2021-06-12 10:14 by Johnson_强生仔仔, 54 阅读, 收藏, 编辑
摘要: 有待总结。 Binary Search: 633, Sum of Square Numbers 475, Heaters 744, Find Smallest Letter Greater than target(LC submissions from original session) 427?? 阅读全文

[LeetCode] 37. Sudoku Solver_Hard tag: BackTracking

2021-06-10 06:52 by Johnson_强生仔仔, 42 阅读, 收藏, 编辑
摘要: Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 阅读全文

[LeetCode] 36. Valid Sudoku_Medium tag: Array

2021-06-09 09:40 by Johnson_强生仔仔, 40 阅读, 收藏, 编辑
摘要: Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the dig 阅读全文

[LeetCode] 10. Regular Expression Matching_Hard tag: backtracking, DP

2021-06-07 20:22 by Johnson_强生仔仔, 48 阅读, 收藏, 编辑
摘要: Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*' where: '.' Matches any single characte 阅读全文

[LeetCode] 22. Generate Parentheses_Medium tag: backtracking

2021-06-07 19:10 by Johnson_强生仔仔, 13 阅读, 收藏, 编辑
摘要: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(() 阅读全文

[LeetCode] 491. Increasing Subsequences_Medium tag: backtracking

2021-06-07 18:10 by Johnson_强生仔仔, 35 阅读, 收藏, 编辑
摘要: Given an integer array nums, return all the different possible increasing subsequences of the given array with at least two elements. You may return t 阅读全文

[LeetCode] 812. Largest Triangle Area_Easy tag: math

2021-06-06 12:43 by Johnson_强生仔仔, 25 阅读, 收藏, 编辑
摘要: You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. Example: Input: points = [[ 阅读全文

[LeetCode] 784. Letter Case Permutation_Medium tag: backtracking

2021-06-06 09:36 by Johnson_强生仔仔, 34 阅读, 收藏, 编辑
摘要: Given a string s, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible stri 阅读全文
点击右上角即可分享
微信分享提示