- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo1247.java
31 lines (28 loc) · 605 Bytes
/
No1247.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
packageAlgorithm.leetcode.String;
/**
*
* Created by tujietg on Nov 4, 2019
*/
publicclassNo1247 {
publicstaticintminimumSwap(Strings1, Strings2) {
inta = 0;
intb = 0;
for (inti = 0; i < s1.length(); i++) {
if (s1.charAt(i) != s2.charAt(i) && s1.charAt(i) == 'x') {
++a;
System.out.println(a);
}
if (s1.charAt(i) != s2.charAt(i) && s1.charAt(i) == 'y') {
++b;
System.out.println(b);
}
}
if (a % 2 == 0 && b % 2 == 0) {
returna / 2 + b / 2;
} elseif (a % 2 == 1 && b % 2 == 1) {
returna / 2 + b / 2 + 2;
} else {
return -1;
}
}
}