#2546

Apply Bitwise Operations to Make Strings Equal

expert · 1005 · lc medium +32 · verified · 42.6% accepted · 262 likes · top 24%

Description

Given two 0-indexed binary strings s and target of equal length, you may repeatedly pick two different indices i and j and simultaneously set s[i] to s[i] OR s[j] and s[j] to s[i] XOR s[j]. Return true if s can be transformed into target using any number of such operations, or false otherwise.

Example 1:

Input: s = "1010", target = "0110"
Output: true
Explanation: We can do the following operations:
- Choose i = 2 and j = 0. We have now s = "0010".
- Choose i = 2 and j = 1. We have now s = "0110".
Since we can make s equal to target, we return true.

Example 2:

Input: s = "11", target = "00"
Output: false
Explanation: It is not possible to make s equal to target with any number of operations.

Code

1
2
3