摘要:
Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we tak 阅读全文
随笔档案-2019年05月
[LeetCode] 167. Two Sum II - Input array is sorted_Easy tag: Hash/Two pointers
2019-05-31 10:22 by Johnson_强生仔仔, 196 阅读, 收藏, 编辑
摘要:
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文
[LeetCode] 126. Word Ladder II_Hard tag: BFS&DFS
2019-05-26 05:33 by Johnson_强生仔仔, 380 阅读, 收藏, 编辑
摘要:
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such th 阅读全文
[LeetCode] 39. Combination Sum_Medium tag: backtracking
2019-05-25 23:14 by Johnson_强生仔仔, 246 阅读, 收藏, 编辑
摘要:
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the 阅读全文
[LeetCode] 40. Combination Sum II_Medium tag: backtracking
2019-05-25 22:55 by Johnson_强生仔仔, 265 阅读, 收藏, 编辑
摘要:
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb 阅读全文
[LeetCode] 131. Palindrome Partitioning_Medium tag: DFS, backtracking, Palindrome
2019-05-25 10:14 by Johnson_强生仔仔, 307 阅读, 收藏, 编辑
摘要:
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example: 这 阅读全文
[Palindrome] Check any substring in a s is a palindrome or not.
2019-05-25 09:57 by Johnson_强生仔仔, 330 阅读, 收藏, 编辑
摘要:
Give a s, need to check every substring whether it is a palindrome or not. Brute Force T: O(n ^3) 我们利用如果s[start] == s[end], 则只需要判断s[start + 1][end - 1 阅读全文
[LeetCode] 52. N-QueensII_Hard tag: DFS, backtracking
2019-05-24 10:40 by Johnson_强生仔仔, 261 阅读, 收藏, 编辑
摘要:
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all 阅读全文
[LeetCode] 51. N-Queens_Hard tag: DFS, backtracking
2019-05-24 10:22 by Johnson_强生仔仔, 238 阅读, 收藏, 编辑
摘要:
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all 阅读全文
[LeetCode] 47. Permutations II_Medium tag: DFS, backtracking
2019-05-24 09:35 by Johnson_强生仔仔, 250 阅读, 收藏, 编辑
摘要:
Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: Input: [1,1,2] Output: [ [1,1,2], [1,2, 阅读全文
[LeetCode] 46. Permutations_Medium tag: DFS, backtracking
2019-05-24 09:27 by Johnson_强生仔仔, 267 阅读, 收藏, 编辑
摘要:
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1, 阅读全文
[LeetCode] 146. LRU Cache_Hard tag: Hash, Linked List
2019-05-18 11:10 by Johnson_强生仔仔, 187 阅读, 收藏, 编辑
摘要:
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 阅读全文
[LeetCode] 128. Longest Consecutive Sequence_Hard tag: Hash 思路:记忆化搜索
2019-05-16 07:31 by Johnson_强生仔仔, 289 阅读, 收藏, 编辑
摘要:
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Examp 阅读全文
[LeetCode] 654. Maximum Binary Tree_Medium tag: stack
2019-05-15 09:24 by Johnson_强生仔仔, 189 阅读, 收藏, 编辑
摘要:
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: Construct the maximum tree by the given array a 阅读全文
[LeetCode] 84. Largest Rectangle in Histogram_Hard tag: stack
2019-05-15 00:20 by Johnson_强生仔仔, 223 阅读, 收藏, 编辑
摘要:
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist 阅读全文
[LeetCode] 232. Implement Queue using Stacks_Easy tag: stack
2019-05-13 05:37 by Johnson_强生仔仔, 273 阅读, 收藏, 编辑
摘要:
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front 阅读全文
[LeetCode] 155. Min Stack_Easy tag: stack
2019-05-13 04:53 by Johnson_强生仔仔, 231 阅读, 收藏, 编辑
摘要:
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov 阅读全文
[LeetCode] 系统刷题8_Data Structure
2019-05-13 04:21 by Johnson_强生仔仔, 286 阅读, 收藏, 编辑
摘要:
Linear data structure Queue used for BFS most of time O(1) for push O(1) for Pop O(1) for Top Stack . 得到第一个左边比该点小的,第一个右边比该点小的 => strict increasing sta 阅读全文
[LeetCode] 75. Sort Colors_Medium tag: Two pointers
2019-05-12 10:22 by Johnson_强生仔仔, 330 阅读, 收藏, 编辑
摘要:
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the or 阅读全文
[LeetCode] 15. 3Sum_Medium tag: Array
2019-05-12 03:51 by Johnson_强生仔仔, 227 阅读, 收藏, 编辑
摘要:
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the s 阅读全文
[LeetCode] 4. Median of Two Sorted Arrays_Hard tag: Array, Binary Search
2019-05-10 11:39 by Johnson_强生仔仔, 192 阅读, 收藏, 编辑
摘要:
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh 阅读全文
[LeetCode] 系统刷题7_Array & numbers & string
2019-05-09 11:22 by Johnson_强生仔仔, 346 阅读, 收藏, 编辑
摘要:
1. 2 D Array 如果是在左上到右下的斜线的话,在同一条斜线上的x - y 相等, (x, y) 是该点的坐标 如果是在左下到右上的斜线的话,在同一条斜线上的x + y 相等, (x, y) 是该点的坐标 ex. [(1, 1), (1, 2), (1, 3)] [(2, 1), (2, 2 阅读全文
[LeetCode] 189. Rotate Array_Easy tag: Array
2019-05-09 11:16 by Johnson_强生仔仔, 195 阅读, 收藏, 编辑
摘要:
Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Note: Try to come up as many solutions as you 阅读全文
[LeetCode] 234. Palindrome Linked List_Easy tag: Linked List
2019-05-06 06:27 by Johnson_强生仔仔, 272 阅读, 收藏, 编辑
摘要:
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: 阅读全文
[LeetCode] 109. Convert Sorted List to Binary Search Tree_Medium tag: Linked List
2019-05-06 05:00 by Johnson_强生仔仔, 275 阅读, 收藏, 编辑
摘要:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced bina 阅读全文
[LeetCode] 138. Copy List with Random Pointer_Medium tag: Linked List
2019-05-04 11:06 by Johnson_强生仔仔, 210 阅读, 收藏, 编辑
摘要:
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy 阅读全文
[LeetCode] 23. Merge k Sorted Lists_Hard tag: Linked List
2019-05-03 11:33 by Johnson_强生仔仔, 177 阅读, 收藏, 编辑
摘要:
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 阅读全文
[LeetCode] 143. Reorder List_Middle tag: Linked List
2019-05-03 10:37 by Johnson_强生仔仔, 300 阅读, 收藏, 编辑
摘要:
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list's nodes, only nodes its 阅读全文
[LeetCode] 148. Sort List_Middle tag: Linked List
2019-05-02 11:11 by Johnson_强生仔仔, 212 阅读, 收藏, 编辑
摘要:
Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4-> 阅读全文
[LeetCode] 21. Merge Two Sorted Lists_Easy tag: Linked List
2019-05-02 10:49 by Johnson_强生仔仔, 257 阅读, 收藏, 编辑
摘要:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: 阅读全文
[LeetCode] 876. Middle of the Linked List_Easy tag: Linked List
2019-05-02 10:12 by Johnson_强生仔仔, 302 阅读, 收藏, 编辑
摘要:
Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middl 阅读全文
[LeetCode] 86. Partition List_Medium tag: Linked List
2019-05-02 09:57 by Johnson_强生仔仔, 256 阅读, 收藏, 编辑
摘要:
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the 阅读全文
[LeetCode] 92. Reverse Linked List II_Medium tag: Linked List
2019-05-01 11:09 by Johnson_强生仔仔, 222 阅读, 收藏, 编辑
摘要:
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: 这个题目是在[LeetCode] 206. Reverse Linked List_Ea 阅读全文