代码改变世界

随笔档案-2021年08月

[LeetCode] 382. Linked List Random Node_Medium tag: linked list, math

2021-08-23 04:36 by Johnson_强生仔仔, 29 阅读, 收藏, 编辑
摘要: Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. Implement the 阅读全文

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

2021-08-22 09:22 by Johnson_强生仔仔, 26 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 31 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 25 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 26 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 34 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 29 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 28 阅读, 收藏, 编辑
摘要: 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 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 21 阅读, 收藏, 编辑
摘要: 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_强生仔仔, 22 阅读, 收藏, 编辑
摘要: 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 阅读全文

[LeetCode] 857. Minimum Cost to Hire K Workers_Hard tag: sort, heap

2021-08-16 10:12 by Johnson_强生仔仔, 34 阅读, 收藏, 编辑
摘要: There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wa 阅读全文

[LeetCode] 849. Maximize Distance to Closest Person_Medium tag: BFS, array

2021-08-12 07:45 by Johnson_强生仔仔, 19 阅读, 收藏, 编辑
摘要: You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that th 阅读全文

[LeetCode] 833. Find And Replace in String_Medium tag: array

2021-08-12 01:47 by Johnson_强生仔仔, 35 阅读, 收藏, 编辑
摘要: Y ou are given a 0-indexed string s that you must perform k replacement operations on. The replacement operations are given as three 0-indexed paralle 阅读全文

[LeetCode] 809. Expressive Words_Medium tag: array, two pointers

2021-08-12 01:16 by Johnson_强生仔仔, 34 阅读, 收藏, 编辑
摘要: Sometimes people repeat letters to represent extra feeling. For example: "hello" -> "heeellooo" "hi" -> "hiiii" In these strings like "heeellooo", we 阅读全文

[LeetCode] 681. Next Closest Time_Medium tag: array, sort

2021-08-10 10:46 by Johnson_强生仔仔, 38 阅读, 收藏, 编辑
摘要: Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit 阅读全文

[LeetCode] 163. Missing Ranges_Easy tag: array

2021-08-10 09:54 by Johnson_强生仔仔, 27 阅读, 收藏, 编辑
摘要: You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are in the inclusive range. A number x is c 阅读全文

[LeetCode] 159. Longest Substring with At Most Two Distinct Characters_Medium tag: Two pointers

2021-08-10 09:21 by Johnson_强生仔仔, 34 阅读, 收藏, 编辑
摘要: Given a string s, return the length of the longest substring that contains at most two distinct characters. Example 1: Input: s = "eceba" Output: 3 Ex 阅读全文

[LeetCode] 158. Read N Characters Given Read4 II - Call multiple times_Hard tag: array, queue

2021-08-09 11:23 by Johnson_强生仔仔, 39 阅读, 收藏, 编辑
摘要: Given a file and assume that you can only read the file using a given method read4, implement a method read to read n characters. Your method read may 阅读全文

[LeetCode] 157. Read N Characters Given Read4_Easy tag: array

2021-08-09 10:35 by Johnson_强生仔仔, 22 阅读, 收藏, 编辑
摘要: Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters. Method read4: The API rea 阅读全文

[LeetCode] 76. Minimum Window Substring_Hard tag: two pointers

2021-08-08 09:27 by Johnson_强生仔仔, 28 阅读, 收藏, 编辑
摘要: Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicat 阅读全文

[LeetCode] 66. Plus One_Easy tag: array

2021-08-08 08:56 by Johnson_强生仔仔, 28 阅读, 收藏, 编辑
摘要: Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer. The digits are stored such that the most 阅读全文

[LeetCode] 48. Rotate Image_Medium tag: array

2021-08-08 04:24 by Johnson_强生仔仔, 9 阅读, 收藏, 编辑
摘要: You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means 阅读全文

[LeetCode] 43. Multiply Strings_Medium tag: string

2021-08-08 00:02 by Johnson_强生仔仔, 27 阅读, 收藏, 编辑
摘要: Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: You mus 阅读全文

[LeetCode] 31. Next Permutation_Medium tag: sort, two pointers

2021-08-07 23:37 by Johnson_强生仔仔, 22 阅读, 收藏, 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such an arrangement is not pos 阅读全文

[LeetCode] 11. Container With Most Water_Medium tag: two pointers

2021-08-05 01:33 by Johnson_强生仔仔, 16 阅读, 收藏, 编辑
摘要: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endp 阅读全文

[LeetCode] 3. Longest Substring Without Repeating Characters_Medium tag: two pointers

2021-08-05 01:24 by Johnson_强生仔仔, 19 阅读, 收藏, 编辑
摘要: Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The a 阅读全文

[LeetCode] 975. Odd Even Jump_Hard tag: stack, dynamic programming

2021-08-04 10:52 by Johnson_强生仔仔, 48 阅读, 收藏, 编辑
摘要: You are given an integer array arr. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called  阅读全文

[LeetCode] 904. Fruit Into Baskets_Medium tag: Two pointers

2021-08-04 10:36 by Johnson_强生仔仔, 46 阅读, 收藏, 编辑
摘要: You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where f 阅读全文

[LeetCode] 482. License Key Formatting_Easy tag: String

2021-08-04 10:29 by Johnson_强生仔仔, 28 阅读, 收藏, 编辑
摘要: You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 gro 阅读全文

[LeetCode] 929. Unique Email Addresses_Easy tag: Hash

2021-08-03 06:42 by Johnson_强生仔仔, 24 阅读, 收藏, 编辑
摘要: Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more  阅读全文
点击右上角即可分享
微信分享提示