Minimum number of given operations required to convert a string to another string | Java implementation of the approach ; Function to return the minimum operations of the given type required to convert string s to string t ; Characters are already equal ; Increment count of 0 s ; Increment count of 1 s ; Driver code
import java . util . * ; class GFG { static int minOperations ( String s , String t , int n ) { int ct0 = 0 , ct1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == t . charAt ( i ) ) continue ; if ( s . charAt ( i ) == '0' ) ct0 ++ ; else ct1 ++ ; } return Math . max ( ct0 , ct1 ) ; } public static void main ( String args [ ] ) { String s = "010" , t = "101" ; int n = s . length ( ) ; System . out . println ( minOperations ( s , t , n ) ) ; } }