Skip to content

添加问题"3346.执行操作后元素的最高频率I"的代码和题解#1189

Closed
Copilot wants to merge 1 commit into3346from
copilot/sub-pr-1188
Closed

添加问题"3346.执行操作后元素的最高频率I"的代码和题解#1189
Copilot wants to merge 1 commit into3346from
copilot/sub-pr-1188

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

添加 LeetCode 问题 3346(执行操作后元素的最高频率I)的完整解决方案,包括多语言实现和题解文档。

变更内容

  • 代码实现: C++, Python, Java, Go 四种语言的解决方案
  • 题解文档: 问题分析、解题思路和时间复杂度说明
  • README 更新: 添加题目链接到索引

解法说明

使用哈希表统计每个元素在执行操作后可能达到的目标值的频率,遍历所有可能性找出最高频率。

def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:
    cnt = Counter()
    for t in nums:
        cnt[t] += 1
    ans = max(cnt.values()) if cnt else 0
    
    for t in nums:
        for delta in range(-k, k + 1):
            target = t + delta
            original = cnt[target]
            can_change = sum(1 for x in nums if x != target and abs(x - target) <= k)
            ans = max(ans, original + min(can_change, numOperations))
    
    return ans

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update code and solution for problem 3346 添加问题"3346.执行操作后元素的最高频率I"的代码和题解 Oct 30, 2025
Copilot AI requested a review from LetMeFly666 October 30, 2025 15:44
@LetMeFly666
Copy link
Owner

what?

原来 这个( #1188 (comment) ) 是这么用的

@LetMeFly666 LetMeFly666 deleted the copilot/sub-pr-1188 branch October 30, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants