GoCalf Calf 的自留地 · 昙花一现

<Code author="Calf" />

  • 100. Same Tree

    #Problem Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. …

    easy
  • 226. Invert Binary Tree

    #Problem Given the root of a binary tree, invert the tree, and return its root. https://leetcode.com/problems/invert-binary-tree/ Example 1: case1Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: case2Input: root = …

    easy
  • 98. Validate Binary Search Tree

    #Problem Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node …

    medium
  • 347. Top K Frequent Elements

    #Problem Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. https://leetcode.com/problems/top-k-frequent-elements/ Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: …

    medium
  • 91. Decode Ways

    #Problem You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> 'A' "2" -> 'B' ... "25" -> 'Y' "26" -> 'Z' However, while decoding the message, you realize that there …

    medium
  • 217. Contains Duplicate

    #Problem Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. https://leetcode.com/problems/contains-duplicate/ Example 1: Input: nums = [1,2,3,1] Output: …

    easy
  • 213. House Robber II

    #Problem You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. …

    medium
  • 3238. Find the Number of Winning Players

    #Problem You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xᵢ, yᵢ] represents that the player xᵢ picked a ball of color yᵢ. Player i wins the game if they pick strictly more than i …

    easy
  • 212. Word Search II

    #Problem 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 sequentially adjacent cells, where adjacent cells are horizontally or vertically …

    hard
  • 211. Design Add and Search Words Data Structure

    #Problem Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: WordDictionary() Initializes the object. void addWord(word) Adds word to the …

    medium
  • 338. Counting Bits

    #Problem Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1’s in the binary representation of i. https://leetcode.com/problems/counting-bits/ Example 1: Input: n = 2 Output: …

    easy
  • 208. Implement Trie (Prefix Tree)

    #Problem 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 various applications of this data structure, such as autocomplete and spellchecker. …

    medium
  • 207. Course Schedule

    #Problem There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [aᵢ, bᵢ] indicates that you must take course bᵢ first if you want to take …

    medium
  • 3233. Find the Count of Numbers Which Are Not Special

    #Problem You are given 2 positive integers l and r. For any number x, all positive divisors of x except x are called the proper divisors of x. A number is called special if it has exactly 2 proper divisors. For example: The number 4 is …

    medium
  • 79. Word Search

    #Problem Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically …

    medium
  • 206. Reverse Linked List

    #Problem Given the head of a singly linked list, reverse the list, and return the reversed list. https://leetcode.com/problems/reverse-linked-list/ Example 1: case1Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: case2Input: head = …

    easy
  • 76. Minimum Window Substring

    #Problem 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 duplicates) is included in the window. If there is no such substring, return the empty …

    hard
  • 73. Set Matrix Zeroes

    #Problem Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0’s. You must do it in place. https://leetcode.com/problems/set-matrix-zeroes/ Example 1: case1Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] …

    medium
  • 200. Number of Islands

    #Problem Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You …

    medium
  • 3248. Snake in Matrix

    #Problem There is a snake in an n x n matrix grid and can move in four possible directions. Each cell in the grid is identified by the position: grid[i][j] = (i * n) + j. The snake starts at cell 0 and follows a sequence of commands. You …

    easy
  • 70. Climbing Stairs

    #Problem You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? https://leetcode.com/problems/climbing-stairs/ Example 1: Input: n = …

    easy
  • 198. House Robber

    #Problem You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems …

    medium
  • 3244. Shortest Distance After Road Addition Queries II

    #Problem You are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1. queries[i] = [uᵢ, vᵢ] represents …

    hard
  • 322. Coin Change

    #Problem You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount …

    medium
  • 191. Number of 1 Bits

    #Problem Given a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight). A set bit refers to a bit in the binary representation of a number that has a value …

    easy
  • 190. Reverse Bits

    #Problem Reverse bits of a given 32 bits unsigned integer. Note: Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not …

    easy
  • 3243. Shortest Distance After Road Addition Queries I

    #Problem You are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1. queries[i] = [uᵢ, vᵢ] represents …

    medium
  • 62. Unique Paths

    #Problem There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or …

    medium
  • 572. Subtree of Another Tree

    #Problem Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtree of a binary tree tree is a tree that consists of a …

    easy
  • 57. Insert Interval

    #Problem You are given an array of non-overlapping intervals intervals where intervals[i] = [startᵢ, endᵢ] represent the start and the end of the iᵗʰ interval and intervals is sorted in ascending order by startᵢ. You are also given an …

    medium
  • 56. Merge Intervals

    #Problem Given an array of intervals where intervals[i] = [startᵢ, endᵢ], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. …

    medium
  • 55. Jump Game

    #Problem You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false …

    medium