MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / buddyStrings

Method buddyStrings

Java/buddy-strings.java:21–49  ·  view source on GitHub ↗
(String A, String B)

Source from the content-addressed store, hash-verified

19 return false;
20 }
21 public boolean buddyStrings(String A, String B) {
22 if(A.length() != B.length()){
23 return false;
24 }
25
26 int count = 0;
27 char ca = 'A';
28 char cb = 'A';
29
30 for(int i=0; i<A.length(); i++){
31 if(A.charAt(i) != B.charAt(i) ){
32 if(count == 0){
33 ca = A.charAt(i);
34 cb = B.charAt(i);
35 }
36 else if(count == 1){
37 if(ca != B.charAt(i) || cb != A.charAt(i)){
38 count++;
39 }
40 }
41 count++;
42 }
43 }
44
45 if(count == 2 || (count == 0 && isDuplicate(A))){
46 return true;
47 }
48 return false;
49 }
50}

Callers

nothing calls this directly

Calls 2

isDuplicateMethod · 0.95
lengthMethod · 0.80

Tested by

no test coverage detected