-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClass.java
More file actions
317 lines (308 loc) · 8.84 KB
/
MainClass.java
File metadata and controls
317 lines (308 loc) · 8.84 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import java.util.ArrayList;
public class MainClass {
public static void main(String[] args) {
//SingleNumber2 sn2 = new SingleNumber2();
//sn2.test();
//ZigZag zz = new ZigZag();
//zz.testZigZag();
//zz.testLevelOrder();
//Candy candy = new Candy();
//candy.testCandy();
//ReverseInteger ri = new ReverseInteger();
//ri.testReverse();
//LevelOrderTraversal lot = new LevelOrderTraversal();
//lot.testLevelOrder();
//PreorderTraversal pt = new PreorderTraversal();
//pt.testPreorder();
//ReorderList rl = new ReorderList();
//rl.testReorder();
//StringToInteger sti = new StringToInteger();
//sti.testAtoI();
//ReversedPolishNotation rpn = new ReversedPolishNotation();
//rpn.testRPN();
//WordBreak wb = new WordBreak();
//wb.testWordBreak();
//InsertSort is = new InsertSort();
//is.testInsertion();
//SortList sl = new SortList();
//sl.testMerge();
//sl.testSortList();
//PascalTriangle2 pt2 = new PascalTriangle2();
//pt2.testTri();
//Triangle t = new Triangle();
//t.testMin();
//SortedListToBST s = new SortedListToBST();
//s.testRecur();
//MaxDepth md = new MaxDepth();
//md.testDepth();
//SumRootToLeaf s = new SumRootToLeaf();
//s.testSum();
//LongestConsecutiveSequence l = new LongestConsecutiveSequence();
//l.testCon();
//Stock2 s = new Stock2();
//s.testStock();
//Stock3 s = new Stock3();
//s.testStock();
//NextRight2 n = new NextRight2();
//n.testNext();
//PathSum ps = new PathSum();
//ps.testSum();
//PathSum2 ps = new PathSum2();
//ps.testSum();
//DistinctSubsequence ds = new DistinctSubsequence();
//ds.testNum();
//MinDepth md = new MinDepth();
//md.testDepth();
//BinaryTreeInorderPostOrder bt = new BinaryTreeInorderPostOrder();
//bt.testBuild();
//BinaryTreeInorderPreorder bt = new BinaryTreeInorderPreorder();
//bt.testBuild();
//SymmetricTree st = new SymmetricTree();
//st.testSymmetric();
//RecoverBST rb = new RecoverBST();
//rb.testRecover();
//UniqueBST ut = new UniqueBST();
//ut.testNum();
//ReverseLinkedList rl = new ReverseLinkedList();
//rl.testReverse();
//Subsets ss = new Subsets();
//ss.testSubsets();
//GrayCode gc = new GrayCode();
//gc.testGray();
//MergeSort ms = new MergeSort();
//ms.testMerge();
//PartitionList pl = new PartitionList();
//pl.testPartition();
//RemoveDuplicates rd = new RemoveDuplicates();
//rd.testDelete();
//RemoveDuplicates2 rd = new RemoveDuplicates2();
//rd.testDelete();
//SearchRotatedArray s = new SearchRotatedArray();
//s.testSearch();
//WordSearch ws = new WordSearch();
//ws.testExist();
//LongestSubWORepeat l = new LongestSubWORepeat();
//l.testLength();
//RemoveElement re = new RemoveElement();
//re.testRemove();
//RemoveDuplicatesFromSortedArray r = new RemoveDuplicatesFromSortedArray();
//r.testRemove();
//MergeTwoSortedLists m = new MergeTwoSortedLists();
//m.testMerge();
//SwapNodesInPair s = new SwapNodesInPair();
//s.testSwap();
//Permutations p = new Permutations();
//p.testPermute();
//SortColors s = new SortColors();
//s.testSort();
//RotateImage r = new RotateImage();
//r.test();
//GenerateParentheses g = new GenerateParentheses();
//g.test();
//LinkedListCycle2 l = new LinkedListCycle2();
//l.test();
//SpiralMatrix2 s = new SpiralMatrix2();
//s.test();
//RemoveDuplicatesFromSortedArray2 r = new RemoveDuplicatesFromSortedArray2();
//r.testRemove();
//PalindromeNumber p = new PalindromeNumber();
//p.test();
//TrappingRainWater t = new TrappingRainWater();
//t.test();
NQueens n = new NQueens();
n.test();
//NQueens2 n = new NQueens2();
//n.test();
//ThreeSumClosest t = new ThreeSumClosest();
//t.test();
//ValidSudoku v = new ValidSudoku();
//v.test();
//SearchForARange s = new SearchForARange();
//s.test();
//CountAndSay c = new CountAndSay();
//c.test();
//CombinationSum c = new CombinationSum();
//c.test();
//Power p = new Power();
//p.test();
//NextPermutation n = new NextPermutation();
//n.test();
//Permutations2 p = new Permutations2();
//p.test();
//PalindromePartitioning p = new PalindromePartitioning();
//p.test();
//EditDistance e = new EditDistance();
//e.test();
//ReverseNodesKGroup r = new ReverseNodesKGroup();
//r.test();
//GasStation g = new GasStation();
//g.test();
//CombinationSum2 c = new CombinationSum2();
//c.test();
//JumpGame2 j = new JumpGame2();
//j.test();
//MergeKSortedLists m = new MergeKSortedLists();
//m.test();
//Anagrams a = new Anagrams();
//a.test();
//FourSum f = new FourSum();
//f.test();
//Sqrt s = new Sqrt();
//s.test();
//PermutationSequence p = new PermutationSequence();
//p.test();
//ScrambleString s = new ScrambleString();
//s.test();
//CopyListRandomPointer c = new CopyListRandomPointer();
//c.test();
//LargestRectangleHistogram l = new LargestRectangleHistogram();
//l.test();
//LongestPalindromicSubstring l = new LongestPalindromicSubstring();
//l.test();
//MergeIntervals m = new MergeIntervals();
//m.test();
//InsertInterval i = new InsertInterval();
//i.test();
//SudokuSolver s = new SudokuSolver();
//s.test();
//RestoreIPAddress r = new RestoreIPAddress();
//r.test();
//MultiplyStrings m = new MultiplyStrings();
//m.test();
//RegularExpressionMatching r = new RegularExpressionMatching();
//r.test();
//BinaryTreeMaxSumPath m = new BinaryTreeMaxSumPath();
//m.test();
//SimplifyPath s = new SimplifyPath();
//s.test();
//InterleavingString i = new InterleavingString();
//i.test();
//LongestValidParentheses l = new LongestValidParentheses();
//l.test();
//PalindromePartitioning2 p = new PalindromePartitioning2();
//p.test();
//MinimumWindowSubstring m = new MinimumWindowSubstring();
//m.test();
//ThreeSum t = new ThreeSum();
//t.test();
//MainClass m = new MainClass();
//m.testHash();
//System.out.println(MainClass.parity("tesqqqqqqqqqqqqqr"));
//MainClass m = new MainClass();
//m.testN();
//MedianOfTwo m = new MedianOfTwo();
//m.test();
//DivideTwoIntegers d = new DivideTwoIntegers();
//d.test();
//DecodeWays d = new DecodeWays();
//d.test();
//WordBreak2 w = new WordBreak2();
//w.test();
//ValidNumber v = new ValidNumber();
//v.test();
WordLadder w = new WordLadder();
w.test();
//WordLadder2 w = new WordLadder2();
//w.test();
//MainClass.testString();
//SurroundedRegions s = new SurroundedRegions();
//s.test();
/*
LRUCache cache = new LRUCache(1);
cache.set(2,1);
cache.get(2);
cache.set(3,2);
cache.get(2);
cache.get(3);
*/
//TextJustification t = new TextJustification();
//t.test();
//WildcardMatching w = new WildcardMatching();
//w.test();
//MaxPointsOnALine m = new MaxPointsOnALine();
//m.test();
//SubstringWithConcatenationOfAllWords s = new SubstringWithConcatenationOfAllWords();
//s.test();
//ZigZagConversion z = new ZigZagConversion();
//z.test();
/*ReverseWordsInString r = new ReverseWordsInString();
r.test();*/
/*Combinations c = new Combinations();
c.test();*/
}
public static void testString() {
ArrayList<String> arr= new ArrayList<String>();
String s = "a";
arr.add(s);
System.out.println(arr.toString());
s = "b";
System.out.println(arr.toString());
}
public void testHash() {
String a = "Aa";
String b = "BBB";
int numa = 0;
int numb = 0;
for (int i = 0; i < a.length(); i++) {
System.out.println(a.charAt(i) + ": " + (int)a.charAt(i) + "; 31 ^ " + (a.length() - 1 - i));
numa += (int)a.charAt(i) * Math.pow(31, a.length() - 1 - i);
System.out.println(numa);
}
System.out.println("\n" + numa);
for (int i = 0; i < b.length(); i++) {
System.out.println(b.charAt(i) + ": " + (int)b.charAt(i) + "; 31 ^ " + (b.length() - 1 - i));
numb += (int)b.charAt(i) * Math.pow(31, b.length() - 1 - i);
System.out.println(numb);
}
System.out.println("\n" + numb);
int ans = 2147483647;
System.out.println(Integer.toBinaryString(ans));
System.out.println(Integer.MAX_VALUE);
String s = null;
s = "test";
System.out.println(s);
System.out.println("hashcode:");
System.out.println("a: " + a + "; code = " + a.hashCode());
System.out.println("b: " + b + "; code = " + b.hashCode());
}
public void testN() {
int n = 9999;
int two = 0;
int five = 0;
for (int i = 2; i <= n; i++) {
while (i % 2 == 0) {
two++;
i = i / 2;
}
while (i % 5 == 0) {
five++;
i = i / 5;
}
}
System.out.println(Math.min(two, five));
}
public static String parity(String s) {
String ans = null;
int n = s.hashCode();
switch (n % 2) {
case 0:
ans = "even";
break;
case 1:
ans = "odd";
break;
}
return ans;
}
public void testMain() {
ListNode head = new ListNode(3);
head.next = new ListNode(5);
head.next.next = new ListNode(7);
inner(head);
inner(head);
}
public void inner(ListNode p) {
System.out.println(p.val);
p = p.next;
}
}