-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIsAnagram.json
More file actions
45 lines (45 loc) · 1.52 KB
/
IsAnagram.json
File metadata and controls
45 lines (45 loc) · 1.52 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
{
"font-normal": "JetBrainsMono-Regular.ttf",
"font-bold": "JetBrainsMono-Bold.ttf",
"font-italic": "JetBrainsMono-BoldItalic.ttf",
"font-bold-italic": "JetBrainsMono-Italic.ttf",
"font-size": 19,
"width-margin": 5,
"height-margin": 5,
"spacing": 1,
"background-color": [
255,
255,
255
],
"source-code": [
" public static String sort(String word) {",
" StringBuilder builder = new StringBuilder(word);",
" for (int i = 1; i < builder.length(); i++) {",
" char temp = builder.charAt(i);",
" int j = i;",
" while (j > 0 && builder.charAt(j - 1) > temp) {",
" builder.setCharAt(j, builder.charAt(j - 1));",
" j--;",
" }",
" builder.setCharAt(j, temp);",
" }",
" return builder.toString();",
" }",
"",
" public static boolean isAnagram(String word1, String word2) {",
" if (word1.length() != word2.length()) {",
" return false;",
" }",
" word1 = sort(word1);",
" word2 = sort(word2);",
"",
" for (int i = 0; i < word1.length(); i++) {",
" if (word1.charAt(i) != word2.charAt(i)) {",
" return false;",
" }",
" }",
" return true;",
" }"
]
}