- 博客(2163)
- 问答 (1)
- 收藏
- 关注
原创 LeetCode //C - 823. Binary Trees With Factors
This problem requires counting the number of different binary trees that can be constructed with a given integer array, where each non-leaf node is equal to the product of the values of its children. The solution uses a dynamic programming approach, first
2025-08-12 07:15:00
333
原创 LeetCode //C - 822. Card Flipping Game
Summary: The problem involves flipping cards to find the smallest integer that is only on the back of some card and not on the front of any card. First, we identify invalid numbers (those appearing on both sides of the same card). Then, we check all remain
2025-08-11 07:15:00
435
原创 LeetCode //C - 821. Shortest Distance to a Character
Summary: This problem requires computing the shortest distance from each character in a string s to the nearest occurrence of a specified character c. The solution involves two passes over the string: Left-to-right pass: Records the distance to the last se
2025-08-10 07:15:00
659
原创 LeetCode //C - 820. Short Encoding of Words
This article solves LeetCode 820 "Short Encoding of Words", which requires finding the shortest reference string length that can encode a given word array. The core idea is to sort the words in descending order by length, and then check whether each longer
2025-08-09 07:15:00
748
原创 LeetCode //C - 819. Most Common Word
This C solution finds the most frequent non-banned word in a paragraph by using a hash table to count word frequencies. It processes the paragraph character by character, extracting words while ignoring punctuation and case differences. The algorithm check
2025-08-08 07:15:00
614
原创 LeetCode //C - 818. Race Car
This problem involves finding the shortest sequence of instructions ('A' for accelerate and 'R' for reverse) for a car to reach a target position on an infinite number line. The car starts at position 0 with speed +1. The solution uses dynamic programming
2025-08-07 07:15:00
755
原创 LeetCode //C - 817. Linked List Components
Summary: The problem involves counting the number of connected components in a linked list where components are defined by consecutive elements present in a given subset nums. The solution uses a boolean array to efficiently check membership in nums. By tr
2025-08-06 07:15:00
772
原创 LeetCode //C - 816. Ambiguous Coordinates
This problem involves reconstructing valid 2D coordinate pairs from a string with removed punctuation. The solution generates all possible valid number formats (integer or decimal) for each possible split of the input string, ensuring no leading/trailing z
2025-08-05 07:15:00
831
原创 LeetCode //C - 815. Bus Routes
This problem involves finding the minimum number of bus routes needed to travel from a source stop to a target stop. The solution uses BFS to explore bus stops level by level, where each level represents taking an additional bus. Key steps: Map each stop t
2025-08-04 07:15:00
806
原创 LeetCode //C - 814. Binary Tree Pruning
This question requires us to prune a binary tree and remove all subtrees that do not contain 1. The solution is to use post-order traversal recursion: first recursively process the left and right subtrees, and then check whether the current node needs to b
2025-08-03 07:15:00
527
原创 LeetCode //C - 813. Largest Sum of Averages
This problem requires partitioning an array into at most k adjacent subarrays to maximize the sum of their averages. The solution uses dynamic programming with a prefix sum array to efficiently compute subarray averages. The dp[i][g] table stores the maxim
2025-08-02 07:15:00
952
原创 LeetCode //C - 812. Largest Triangle Area
This problem calculates the largest triangle area formed by any three distinct points on a 2D plane. The solution involves examining all possible triplets of points using three nested loops. For each triplet, the area is computed using the Shoelace formula
2025-08-01 07:15:00
794
原创 LeetCode //C - 811. Subdomain Visit Count
Algorithm Summary: The solution counts subdomain visits by parsing each input string into a visit count and domain, then iteratively processes all possible subdomains (e.g., "discuss.leetcode.com" → "leetcode.com" → "com"). A
2025-07-31 07:15:00
1354
原创 LeetCode //C - 810. Chalkboard XOR Game
Summary: The problem involves a game where Alice and Bob take turns removing numbers from a chalkboard, with Alice starting first. A player loses if their move makes the XOR of all remaining numbers zero. The solution checks two conditions: if the initial
2025-07-30 07:15:00
621
原创 LeetCode //C - 809. Expressive Words
This problem checks if query words can be stretched to match a target string s by extending character groups (3+ identical letters). The solution involves: Group Matching: For each word, compare character groups between s and the word. Stretching Rules: If
2025-07-29 07:15:00
864
原创 LeetCode //C - 808. Soup Servings
This article discusses a problem about the probability of assigning two soups (A and B). Initially, there are n milliliters of soup each, and there are four choices for each operation, with a probability of 0.25 for each operation. When the operation canno
2025-07-28 07:15:00
990
原创 LeetCode //C - 807. Max Increase to Keep City Skyline
Summary: The problem requires maximizing the height increase of buildings in an n x n grid without altering the city's skyline from any cardinal direction. The skyline is determined by the tallest buildings in each row and column. For each building at posi
2025-07-27 07:15:00
633
原创 LeetCode //C - 805. Split Array With Same Average
This problem requires judging whether a given integer array can be divided into two non-empty sub-arrays so that their average values are equal. To avoid floating-point operations, we use mathematical transformation: as long as sum * n == totalSum * k (w
2025-07-26 00:15:00
635
原创 LeetCode //C - 806. Number of Lines To Write String
This problem calculates how many lines are needed to write a string s using given character widths, with each line not exceeding 100 pixels. The solution tracks the line count and current line width. For each character, it checks if adding its width exceed
2025-07-25 07:15:00
728
原创 LeetCode //C - 804. Unique Morse Code Words
Summary: The problem requires counting the number of unique Morse code transformations for a given list of words. Each letter is converted to its Morse code equivalent, and the transformations are formed by concatenating these codes. A hash set is used to
2025-07-24 07:15:00
1158
原创 LeetCode //C - 803. Bricks Falling When Hit
Summary: This problem involves simulating the effect of removing bricks from a grid and determining how many other bricks become unstable and fall as a result. The solution employs a Union-Find data structure to efficiently manage connectivity between bric
2025-07-23 07:15:00
1147
原创 LeetCode //C - 802. Find Eventual Safe States
This question requires finding all safe nodes in a directed graph. A safe node is defined as a node where all paths from the node eventually lead to a terminal node (a node with no outgoing edges) or other safe nodes. The following is a summary of the solu
2025-07-22 07:15:00
912
原创 LeetCode //C - 801. Minimum Swaps To Make Sequences Increasing
Abstract: This paper discusses how to make two arrays strictly increasing by the minimum number of swap operations. Given two arrays nums1 and nums2 of the same length, each operation allows the elements in the same position to be swapped. The solution use
2025-07-21 07:15:00
852
原创 LeetCode //C - 799. Champagne Tower
This problem simulates pouring champagne into a pyramid-shaped glass tower, where excess liquid from each glass spills equally into the two glasses below. The solution uses dynamic programming to track the champagne amount in each glass. For each glass, if
2025-07-20 07:15:00
664
原创 LeetCode //C - 798. Smallest Rotation with Highest Score
Solution Summary: The problem involves finding the optimal rotation index k for an array nums to maximize the score, where the score is the count of elements less than or equal to their new index after rotation. Key Steps: Difference Array: Use a differenc
2025-07-19 07:15:00
621
原创 LeetCode //C - 797. All Paths From Source to Target
This problem requires finding all possible paths from node 0 to node (n-1) in a directed acyclic graph (DAG). The solution uses Depth-First Search (DFS) to explore each path recursively. A temporary path array tracks the current traversal, and when the tar
2025-07-18 07:15:00
1240
原创 LeetCode //C - 796. Rotate String
Summary: The problem checks if string s can be rotated to match string goal by shifting its leftmost character to the right any number of times. The solution first verifies if s and goal have the same length. If they do, it concatenates s with itself and c
2025-07-17 07:15:00
284
原创 LeetCode //C - 795. Number of Subarrays with Bounded Maximum
This problem requires calculating the number of consecutive subarrays in an array that satisfy the maximum value of the subarray within a given interval. The core idea is to use the sliding window technology to efficiently count valid subarrays by maintain
2025-07-16 07:15:00
1736
原创 LeetCode //C - 794. Valid Tic-Tac-Toe State
This problem verifies whether a given Tic-Tac-Toe board state is legal. A legal state must meet the following conditions:Correct turn order: X goes first, O goes second, and the number of Xs must be equal to or one more than O.The win-lose state is leg
2025-07-15 07:15:00
694
原创 LeetCode //C - 793. Preimage Size of Factorial Zeroes Function
Abstract:The question requires calculating the number of non-negative integers x whose number of trailing zeros in factorial equals k. The key idea is to use binary search to determine the smallest x such that f(x)=k. If such an x exists, then 5 consecu
2025-07-14 07:15:00
569
原创 LeetCode //C - 792. Number of Matching Subsequences
Summary: This solution efficiently counts the number of words in a given list that are subsequences of a string s. It uses a queue-based approach where words are initially grouped by their first character. As each character in s is processed, words waiting
2025-07-13 07:15:00
1434
原创 LeetCode //C - 791. Custom Sort String
The problem requires custom sorting string s based on the order of characters in string order. Approach: Count Frequencies: Use an array to count how often each character appears in s. Build Result: Traverse order and append characters from s in the specif
2025-07-12 07:15:00
621
原创 LeetCode //C - 790. Domino and Tromino Tiling
Summary: This problem counts the ways to tile a 2×n board using domino and tromino shapes, allowing rotations. The solution employs dynamic programming with base cases for n=0 (1 way), n=1 (1 way), and n=2 (2 ways). The recurrence relation dp[i] = dp[i-1]
2025-07-11 07:15:00
2115
原创 LeetCode //C - 789. Escape The Ghosts
Summary: The problem determines if a player can escape ghosts in a 2D grid by reaching a target before any ghost. The solution hinges on comparing Manhattan distances: the player's distance from the target versus each ghost's distance. If any ghost can rea
2025-07-10 00:30:00
891
原创 LeetCode //C - 788. Rotated Digits
Summary: The problem requires counting "good" numbers between 1 and n. A good number becomes a different valid number when each digit is rotated 180 degrees. Valid digits include 0, 1, 8 (unchanged), 2, 5, 6, 9 (rotated to each other), while 3, 4
2025-07-09 04:15:00
932
原创 LeetCode //C - 787. Cheapest Flights Within K Stops
Summary: The problem requires finding the cheapest flight path from a source city to a destination city with at most k stops. Using a modified Bellman-Ford algorithm, the solution iteratively relaxes all flight edges for k+1 iterations (representing k stop
2025-07-08 07:15:00
1257
原创 LeetCode //C - 786. K-th Smallest Prime Fraction
This problem finds the k-th smallest fraction formed by dividing elements from a sorted array of primes (with 1). The solution uses a min-heap approach to efficiently track fractions without generating all possible pairs. Key steps: Initialize a heap with
2025-07-07 07:00:00
654
原创 LeetCode //C - 785. Is Graph Bipartite?
Abstract:Determine whether an undirected graph is bipartite. A bipartite graph requires that the nodes can be divided into two sets, and each edge connects nodes in different sets. Use DFS or BFS to traverse the graph, mark the nodes with two colors, and
2025-07-06 06:00:00
574
原创 LeetCode //C - 784. Letter Case Permutation
This problem generates all possible permutations of a string by changing letter cases while keeping digits unchanged. The solution uses backtracking: for each character, it recursively explores both lowercase and uppercase versions if it's a letter, or kee
2025-07-05 07:15:00
245
原创 LeetCode //C - 783. Minimum Distance Between BST Nodes
Problem Summary: Given a Binary Search Tree (BST), find the smallest difference between any two distinct node values. Solution Approach: The solution uses in-order traversal to visit nodes in ascending order. By keeping track of the previous node value dur
2025-07-04 07:15:00
1504
空空如也
在函数中产生的指针变量无法在函数指针的参数中传递。
2023-10-09
用指向指针的指针动态分配二维数组后,再用指向指针的指针输入数据和输出数据出现问题。
2019-09-16
TA创建的收藏夹 TA关注的收藏夹
TA关注的人