代码改变世界

[LeetCode] 259. 3Sum Smaller_Medium tag: Two pointers

2021-08-22 09:22 by Johnson_强生仔仔, 26 阅读, 0 推荐, 收藏, 编辑
摘要:Given an array of n integers nums and an integer target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition  阅读全文

[LeetCode] 59. Spiral Matrix II_Medium tag: array, DFS

2021-08-22 07:23 by Johnson_强生仔仔, 30 阅读, 0 推荐, 收藏, 编辑
摘要:Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: Input: n = 3 Output: [[1,2,3],[8,9, 阅读全文

[LeetCode] 54. Spiral Matrix_Medium tag: array, DFS

2021-08-22 07:13 by Johnson_强生仔仔, 24 阅读, 0 推荐, 收藏, 编辑
摘要:Given an m x n matrix, return all elements of the matrix in spiral order. Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7, 阅读全文

[LeetCode] 766. Toeplitz Matrix_Easy tag: array

2021-08-22 02:34 by Johnson_强生仔仔, 22 阅读, 0 推荐, 收藏, 编辑
摘要:Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top-left to bottom- 阅读全文

[LeetCode] 289. Game of Life_Medium tag: array

2021-08-21 23:58 by Johnson_强生仔仔, 33 阅读, 0 推荐, 收藏, 编辑
摘要:According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Hort 阅读全文

[LeetCode] 663. Equal Tree Partition_Medium tag: DFS, divide and conquer

2021-08-21 22:18 by Johnson_强生仔仔, 27 阅读, 0 推荐, 收藏, 编辑
摘要:Given the root of a binary tree, return true if you can partition the tree into two trees with equal sums of values after removing exactly one edge on 阅读全文

[LeetCode] 951. Flip Equivalent Binary Trees_Medium tag: DFS, divide and conquer

2021-08-21 21:00 by Johnson_强生仔仔, 26 阅读, 0 推荐, 收藏, 编辑
摘要:For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees. A binary tree X is flip e 阅读全文

[LeetCode] 753. Cracking the Safe_Hard tag: DFS, backtracking

2021-08-19 10:11 by Johnson_强生仔仔, 31 阅读, 0 推荐, 收藏, 编辑
摘要:There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1]. The safe has a peculi 阅读全文

[LeetCode] 399. Evaluate Division_Medium tag: DFS

2021-08-18 23:14 by Johnson_强生仔仔, 20 阅读, 0 推荐, 收藏, 编辑
摘要:You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equa 阅读全文

[LeetCode] 222. Count Complete Tree Nodes_Medium tag: Binary search

2021-08-18 08:57 by Johnson_强生仔仔, 21 阅读, 0 推荐, 收藏, 编辑
摘要:Ideas: 1. T: O(n), S: O(lgn), depth of the tree # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=No 阅读全文
上一页 1 2 3 4 5 6 ··· 39 下一页