wordpress按条件搜索功能,上海外包seo,中国纪检监察报社社长,定制化开发是什么意思文章目录1. 题目2. 解题1. 题目 
给你一个字符串数组 nums #xff0c;该数组由 n 个 互不相同 的二进制字符串组成#xff0c;且每个字符串长度都是 n 。 请你找出并返回一个长度为 n 且 没有出现 在 nums 中的二进制字符串。 如果存在多种答案#xff0c;只需返回 任意一个…
文章目录1. 题目2. 解题1. 题目 
给你一个字符串数组 nums 该数组由 n 个 互不相同 的二进制字符串组成且每个字符串长度都是 n 。 请你找出并返回一个长度为 n 且 没有出现 在 nums 中的二进制字符串。 如果存在多种答案只需返回 任意一个 即可。 
示例 1
输入nums  [01,10]
输出11
解释11 没有出现在 nums 中。00 也是正确答案。示例 2
输入nums  [00,01]
输出11
解释11 没有出现在 nums 中。10 也是正确答案。示例 3
输入nums  [111,011,001]
输出101
解释101 没有出现在 nums 中。000、010、100、110 也是正确答案。提示
n  nums.length
1  n  16
nums[i].length  n
nums[i] 为 0 或 1来源力扣LeetCode 链接https://leetcode-cn.com/problems/find-unique-binary-string 著作权归领扣网络所有。商业转载请联系官方授权非商业转载请注明出处。 2. 解题 
转成数字哈希存储遍历 0 - 216 找到不存在的转成2进制前面补零 
class Solution {
public:string findDifferentBinaryString(vectorstring nums) {unordered_setint s;string ans;for(auto n : nums){int number  0;for(char c : n){number  number*2(c-0);}s.insert(number);}for(int i  0; i  (116); i)if(!s.count(i)){ans  convert01(i);while(ans.size()  nums[0].size()){ans.insert(ans.begin(),0);}return ans;}return ;}string convert01(int x){string ans  ;while(x){if(x1) ans  1;else ans  0;x  1;}reverse(ans.begin(), ans.end());return ans;}
};4 ms 10 MB C 我的CSDN博客地址 https://michael.blog.csdn.net/ 
长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步