leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 0adb20e2b5d21cd803e5214412eec724c4a797d2
parent 20caf1440591f722863e4de9da3402ffc9da8204
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Fri,  2 Jun 2023 11:54:41 -0500

Completed find unique binary string using Backtracking, DFS, and Dart.

Diffstat:
Afind-unique-binary-string/find-unique-binary-string.dart | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/find-unique-binary-string/find-unique-binary-string.dart b/find-unique-binary-string/find-unique-binary-string.dart @@ -0,0 +1,29 @@ +//Given a list of strings (nums) return any combination +//of 1's and 0's that does not appear in the nums list. + +//To solve this I used DfS because it is the best way to +//find the first solution to a problem (not necessarily +//the shortest solution though, but here that does not matter). + +//Time: 260ms Beats: 100% +//Memory: 141.5MB Beats: 100% +class Solution { + String findDifferentBinaryString(List<String> nums) { + Set<String> vals = nums.toSet(); + return findUnique(vals,'', nums[0].length); +} + String findUnique(Set<String> vals, String current, int len){ + if(current.length == len){ + if(vals.contains(current) == false){ + return current; + } + return ''; + } + String one = findUnique(vals, current + '1', len); + if(one.length != 0){ + return one; + } + String zero = findUnique(vals, current + '0', len); + return zero; + } +}