add Solution for 3739.Count Sub Arrays With Majority Elements II#110
Merged
hoangdao3 merged 1 commit intoJun 26, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds the repository’s write-up and index entry for LeetCode 3739. Count Subarrays With Majority Element II, including an accompanying problem description document and a new internal “add-solution” skill guide under .claude/.
Changes:
- Added a new Hard solution write-up for problem 3739 (with Go + Rust implementations and explanation).
- Added a
description.mdfor problem 3739 with examples and constraints. - Updated
README.mdtotals and Hard table to include the new problem link; added an.claudeskill document to codify add-solution conventions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| README.md | Updates overall solution counts and adds the 3739 entry to the Hard index table. |
| Hard/3739.Count-Subarrays-With-Majority-Element-II/solution.md | Adds the algorithm explanation and Go/Rust reference implementations. |
| Hard/3739.Count-Subarrays-With-Majority-Element-II/description.md | Adds the problem statement, examples, and constraints in repo format. |
| .claude/skills/add-solution/SKILL.md | Adds internal guidance for consistently adding future solutions and updating the index. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ## Solutions index | ||
|
|
||
| Total: **159** problems with at least one solution file. | ||
| Total: **160** problems with at least one solution file. |
Comment on lines
+49
to
+67
| func countMajoritySubarrays(nums []int, target int) int64 { | ||
| n := len(nums) | ||
| prefix := make([]int, 2*n+1) | ||
| prefix[n] = 1 | ||
| count := n | ||
| ans, sum := 0, 0 | ||
| for _, num := range nums { | ||
| if num == target { | ||
| sum += prefix[count] | ||
| count++ | ||
| } else { | ||
| count-- | ||
| sum -= prefix[count] | ||
| } | ||
| prefix[count]++ | ||
| ans += sum | ||
| } | ||
| return int64(ans) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.