forked from CS3704-VT/tech-interview-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode (unfinished)
More file actions
64 lines (47 loc) · 1.6 KB
/
Code (unfinished)
File metadata and controls
64 lines (47 loc) · 1.6 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Solution {
public boolean closeStrings(String word1, String word2) {
int differences = 0;
int word1_length = word1.length();
int word2_length = word2.length();
char[] arr1 = new char[word1_length];
char[] arr2 = new char[word2_length];
if (word1_length != word2_length)
return false;
else
{
int count1 = 0;
int count2 = 0;
for (int i = 0; i < word1_length; i++) {
char current_char1 = word1.charAt(i);
char current_char2 = word2.charAt(i);
arr1[i] = current_char1;
arr2[i] = current_char2;
if (current_char1 != current_char2) {
if (differences == 0) {
count1 = i;
}
if (differences == 1) {
count2 = i;
}
differences = differences + 1;
}
}
if (differences == 2) //check to see if swapping fixes
{
if ((arr1[count1] == arr2[count2]) && (arr1[count2] == arr2[count1])) {
return true;
}
}
else {
for (int k = 0; k < arr1.length(); k++) {
arr1[]
}
if () //changing works {
return true;
}
else {
return false;
}
}
}
}