File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* Given an array of strings nums containing n unique binary strings each of length n,
2+ return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.
3+ https://leetcode.com/problems/find-unique-binary-string/*/
4+ class Solution {
5+ public String findDifferentBinaryString (String [] nums ) {
6+
7+ int len =nums [0 ].length ();
8+ String ans ="" ,ans1 ="" ;
9+ for (int i =0 ;i <=Math .pow (2 ,len )-1 ;i ++)
10+ {
11+ ans =Integer .toBinaryString (i ); //converting to binary sting equivalent to number
12+ int l =ans .length ();
13+ int a =len -l ;
14+ if (a >0 )
15+ ans1 =String .format ( "%0" +a + "d%s" , 0 , ans ); //adding zeros before the conferted string
16+ else
17+ ans1 =ans ;
18+ int cnt =0 ;
19+ for (int j =0 ;j <len ;j ++)
20+ {
21+ if (!nums [j ].equals (ans1 )) //checking if the string is present in array or not
22+ cnt ++;
23+ }
24+ if (cnt ==len ) //checking condition and returning the answer
25+ return ans1 ;
26+ }
27+
28+ return ans1 ;
29+
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments