Skip to content

Commit 137ca85

Browse files
committed
Renamed variables to make more sense
1 parent d60e416 commit 137ca85

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/main/java/com/rampatra/strings/AnagramsTogether.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515
public class AnagramsTogether {
1616

1717
/**
18-
* Prints all the anagrams together from the string
19-
* array {@param s}.
18+
* Prints all the anagrams together from the string array {@code strings}.
2019
* <p/>
2120
* Anagrams are words consisting of the same letters but in the same or different
2221
* order. For example, "cat" and "tac" are anagrams. Same as "god" and "dog".
2322
*
24-
* @param s
23+
* @param strings
2524
*/
26-
private static void printAnagramsTogether(String[] s) {
25+
private static void printAnagramsTogether(String[] strings) {
2726

2827
// each key holds all the indexes of a anagram
2928
HashMap<String, List<Integer>> hashMap = new HashMap<>();
3029

31-
for (int i = 0; i < s.length; i++) {
32-
char[] chars = s[i].toCharArray();
30+
for (int i = 0; i < strings.length; i++) {
31+
char[] chars = strings[i].toCharArray();
3332
Arrays.sort(chars);
3433

3534
List<Integer> indexes = hashMap.get(String.valueOf(chars));
@@ -42,7 +41,7 @@ private static void printAnagramsTogether(String[] s) {
4241

4342
for (Map.Entry<String, List<Integer>> entry : hashMap.entrySet()) {
4443
for (int i = 0; i < entry.getValue().size(); i++) {
45-
System.out.println(s[entry.getValue().get(i)]);
44+
System.out.println(strings[entry.getValue().get(i)]);
4645
}
4746
System.out.println("------");
4847
}
@@ -52,4 +51,4 @@ public static void main(String[] args) {
5251
printAnagramsTogether(new String[]{"cat", "dog", "tac", "god", "act"});
5352
printAnagramsTogether(new String[]{"cat", "tac", "act", "god", "dog"});
5453
}
55-
}
54+
}

src/main/java/com/rampatra/strings/AnagramsTogetherLexicographically.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*
88
* @author rampatra
99
* @since 10/11/15
10-
* @time: 7:56 PM
1110
*/
1211
public class AnagramsTogetherLexicographically {
1312

@@ -30,8 +29,8 @@ public static void printAnagramsTogether(String[] strings) {
3029
});
3130

3231
for (int i = 0; i < strings.length; i++) {
33-
String removeSpaces = strings[i].replaceAll("\\s+", "");
34-
char[] chars = removeSpaces.toCharArray();
32+
String spaceRemovedStr = strings[i].replaceAll("\\s+", "");
33+
char[] chars = spaceRemovedStr.toCharArray();
3534
Arrays.sort(chars);
3635

3736
List<Integer> indexes = hashMap.get(String.valueOf(chars));

0 commit comments

Comments
 (0)