-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloWorld.java
153 lines (119 loc) · 2.63 KB
/
HelloWorld.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.util.Arrays;
public class HelloWorld {
static boolean uniqueChars(String input){
if(input.length() > 256)
return false;
boolean []array = new boolean[256];
for(int i = 0; i < input.length(); i++){
int value = input.charAt(i);
if(array[value]){
return false;
}
else{
array[value] = true;
}
}
return true;
}
static void reverse(String str){
StringBuffer buffer = new StringBuffer();
for(int i = str.length();i > 0; i--){
buffer.append(str.charAt(i-1));
}
str = buffer.toString();
System.out.println(str);
}
static String reverseRecursive(String str){
if(str.length() == 1){
return str;
}
return str.charAt(str.length()-1) + reverseRecursive(str.substring(0,str.length()-1));
}
static boolean isSubstring(String a, String b){
if(b.length() > a.length()){
String temp = b;
b = a;
a = temp;
}
for(int i = 0; i + b.length() - 1 < a.length(); i++){
if(a.substring(i, i+b.length()).equals(b))
return true;
}
return false;
}
static boolean permutation(String a, String b){
if(b.length() != a.length()){
return false;
}
a = sort(a);
b = sort(b);
if(a.equals(b))
return true;
return false;
}
private static String sort(String b) {
char[] t = b.toCharArray();
Arrays.sort(t);
return new String(t);
}
static boolean permutationF(String a, String b){
if(b.length() != a.length()){
return false;
}
int charCountsA[] = new int[256];
int charCountsB[] = new int[256];
for(int i = 0; i < a.length(); i++){
charCountsA[a.charAt(i)]++;
charCountsB[b.charAt(i)]++;
}
for(int i = 0; i < 256; i++){
if(charCountsA[i] != charCountsB[i]){
return false;
}
}
return true;
}
static char[] replaceString(char[] str){
for(int i = 0; i < str.length; i++){
}
return str;
}
static boolean isRotation(String s1, String s2){
return isSubstring(s1+s1, s2);
}
public static void main(String[] args) {
SinglyLinkedList list = new SinglyLinkedList(5);
list.print();
list = new SinglyLinkedList();
list.print();
list.insert(1);
list.print();
list.insert(2);
list.print();
list.insert(3);
list.insert(4);
list.print();
list.reverse();
list.print();
list.insert(5);
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
list.removeMiddle();
list.print();
}
}