惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
小众软件
小众软件
The Cloudflare Blog
S
SegmentFault 最新的问题
美团技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
博客园 - 聂微东
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
WordPress大学
WordPress大学
T
Tailwind CSS Blog
腾讯CDC
人人都是产品经理
人人都是产品经理
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
J
Java Code Geeks
宝玉的分享
宝玉的分享

ABB00717

SecList Knock Pivoting and Tunneling Broken Authentication File Inclusion Login Brute Forcing Reverse Shell Web Fuzzing HTB - SpeedNet PHP Filter to RCE Redis HTB - Pollution HTB - Pollution 工具 常見服務 HTB - BroScience HTB - BroScience 如何把爛爛的 shell 升級成好用的 TTY 滲透筆記 HTB - Imagery HTB - Imagery HTB - Reset HTB - Reset HTB - Trick HTB - Trick HTB - Editorial HTB - Editorial 150. Evaluate Reverse Polish Notation droopescan 安裝找不到 module imp 解決「桌面背景被當成一個視窗不斷重新彈出並覆蓋其他視窗」的問題
1980. Find Unique Binary String
2026-03-08 · via ABB00717

https://leetcode.com/problems/find-unique-binary-string/description

每次看到位元操作都會直覺想到 XOR,但這題沒有,直接枚舉並檢查就好了:

from typing import List
 
 
class Solution:
    def findDifferentBinaryString(self, nums: List[str]) -> str:
        n = len(nums[0])
        dict = {}
        for num in nums:
            dict[int(num, 2)] = True
 
        for num in range(pow(2, n)):
            if dict.get(num) == None:
                return f"{num:0{n}b}"
 
        return ""

但還可以更好,如果腦袋想到 dict = True or False,都應該要換成 Set 才對。再來,根據鴿籠原理(Pigeonhole Principle),我們最多只會需要遍歷 n+1 次就可以找到答案了。

from typing import List
 
 
class Solution:
    # len(nums) is expected to be equal to len(nums[i])
    def findDifferentBinaryString(self, nums: List[str]) -> str:
        n = len(nums)
        set = ()
 
        seen = [int(num, 2) for num in nums]
 
        # Base on Pigeonhole Principle, we only have to
        # enumerate until len(nums)+1 instead of limit(n)+1
        for num in range(n + 1):
            if num not in seen:
                return f"{num:0{n}b}"
 
        return ""

咦?我 2025-02-20 有解過?

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
class Solution {
public:
    std::string findDifferentBinaryString(std::vector<std::string> &nums) {
        int n = nums.size();
    
        std::string result;
        for (int i = 0; i < n; i++) {
            result += nums[i][i] == '0' ? '1' : '0';
        }
    
        return result;
    }
};

窩靠 … 只要每個列都挑一個不一樣的位元,那最後組合起來的就必是之前沒有的組合!

我那時怕不是個天才!