XOR Strings 2

Sort by

recency

|

233 Discussions

|

  • + 0 comments
    def strings_xor(s, t):
    res = ""
    for i in range(len(s)):
        if s[i] == t[i]:
            res += '0'
        else:
            res += '1'
    return res
    

    String concatenation works, you only change 3 things at once

  • + 0 comments

    Not working in Python either, the provided output equals the expected one but the checking system is not working.

  • + 0 comments

    I got the correct answer in Java, but it still said "Wrong Answer." The problem says that you cannot add any lines of code, only debug, but there's no lines of code for Java? What's up with that? I'm trying to prepare for a Java coding interview, but I can't use Java to solve this question? The Python solution is so simple, you don't even use XOR. What's the point of this question in the first place? I guess the lesson learned here is "if you're having trouble solving the question, just switch coing languages?"

  • + 0 comments

    Here is the solution for XOR Strings 2 in Java7 because for Java 8 they did not give any code to modify but we have to modiy only 3 lines according to question.

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static String stringsXOR(String s, String t) {
        String res = new String("");
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) != t.charAt(i))
                res += "1";
            else
                res += "0";
        }
    
        return res;
    }
    
    public static void main(String[] args) {
    
        String s, t;
        Scanner in = new Scanner(System.in);
        s = in.nextLine();
        t = in.nextLine();
        System.out.println(stringsXOR(s, t));
    
    }
    

    }

  • + 0 comments

    Don't do it in Javascript, it's broken. The python solution is so simple you'll laugh.