Class Solution
- java.lang.Object
-
- g2501_2600.s2546_apply_bitwise_operations_to_make_strings_equal.Solution
-
public class Solution extends Object
2546 - 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 = “**001**0”.
-
Choose i = 2 and j = 1. We have now s = “0**11**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.length2 <= n <= 105sandtargetconsist of only the digits0and1.
- Choose two different indices
-
-
Constructor Summary
Constructors Constructor Description Solution()
-