Skip to content

Commit fa71eac

Browse files
committed
StringXOR Debug and fine solution
1 parent 63f2085 commit fa71eac

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
-1.8 KB
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package hackerRank_JavaProblemSolving;
2+
3+
import java.util.*;
4+
5+
public class Problem105_StringsXOR_Debug_PlusPlus {
6+
7+
// More efficient proposal
8+
public static String stringsXOREfficientSolution(String s, String t) {
9+
StringBuilder sb = new StringBuilder();
10+
for(int i = 0; i < s.length(); i++) {
11+
if(s.charAt(i) != t.charAt(i)) {
12+
sb.append('1');
13+
} else {
14+
sb.append('0');
15+
}
16+
}
17+
return sb.toString().trim();
18+
} // stringsXOREfficientSolution
19+
20+
// Debugged and submitted
21+
public static String stringsXOR(String s, String t) {
22+
String res = new String("");
23+
for(int i = 0; i < s.length(); i++) {
24+
if(s.charAt(i) == t.charAt(i))
25+
res += "0";
26+
else
27+
res += "1";
28+
}
29+
30+
return res;
31+
}
32+
33+
public static void main(String[] args) {
34+
35+
String s, t;
36+
Scanner in = new Scanner(System.in);
37+
s = in.nextLine();
38+
t = in.nextLine();
39+
System.out.println(stringsXOR(s, t));
40+
41+
}
42+
43+
}

0 commit comments

Comments
 (0)