Class Solution
-
- All Implemented Interfaces:
public final class Solution2546 - Apply Bitwise Operations to Make Strings Equal\.
Medium
You are given two 0-indexed binary strings
sandtargetof the same lengthn. You can do the following operation onsany number of times:Choose two different indices
iandjwhere0 <= i, j < n.Simultaneously, replace
s[i]with (s[i]ORs[j]) ands[j]with (s[i]XORs[j]).
For example, if
s = "0110", you can choosei = 0andj = 2, then simultaneously replaces[0]with (s[0]ORs[2]=0OR1=1), ands[2]with (s[0]XORs[2]=0XOR1=1), so we will haves = "1110".Return
trueif you can make the stringsequal totarget, orfalseotherwise.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 = "**<ins>0</ins>0<ins>1</ins>**0".
Choose i = 2 and j = 1. We have now s = "0**<ins>11</ins>**0". 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.
Constraints:
n == s.length == target.length<code>2 <= n <= 10<sup>5</sup></code>
sandtargetconsist of only the digits0and1.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanmakeStringsEqual(String s, String target)-
-
Method Detail
-
makeStringsEqual
final Boolean makeStringsEqual(String s, String target)
-
-
-
-