aboutsummaryrefslogtreecommitdiff
path: root/find_unique_binary_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'find_unique_binary_str.c')
-rw-r--r--find_unique_binary_str.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/find_unique_binary_str.c b/find_unique_binary_str.c
new file mode 100644
index 0000000..e7e0541
--- /dev/null
+++ b/find_unique_binary_str.c
@@ -0,0 +1,31 @@
+// 1980. Find Unique Binary String
+#include "leetcode.h"
+
+/*
+ * given an array of strings 'nums' containing 'n' unique binary strings each of
+ * length 'n', return a binary string of length 'n' that does not appear in
+ * 'nums'. if there are multiple answers, you may return any of them.
+ */
+
+// char *findDifferentBinaryString(char **nums, int nums_size) {
+char *findDifferentBinaryString(int nums_size,
+ char nums[nums_size][nums_size]) {
+ char *ans = malloc(nums_size + 1);
+ int j = 0;
+ for (int i = 0; i < nums_size; i++) {
+ if (nums[i][i] == '0')
+ ans[j++] = '1';
+ else
+ ans[j++] = '0';
+ }
+ ans[j] = '\0';
+ return j ? ans : "";
+}
+
+int main() {
+ char n1[2][2] = {{"01"}, {"10"}}, n2[2][2] = {{"00"}, {"01"}},
+ n3[3][3] = {{"111"}, {"011"}, {"001"}};
+ printf("%s\n", findDifferentBinaryString(2, n1)); // expect: 11
+ printf("%s\n", findDifferentBinaryString(2, n2)); // expect: 11
+ printf("%s\n", findDifferentBinaryString(3, n3)); // expect: 101
+}