File tree Expand file tree Collapse file tree 3 files changed +16
-18
lines changed
test/java/ssj/algorithm/string Expand file tree Collapse file tree 3 files changed +16
-18
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ public static <T extends Comparable<T>> T min(T... arr) {
90
90
91
91
T min_value = arr [0 ];
92
92
for (T ele : arr ) {
93
- if (min_value .compareTo (ele ) < 0 ) {
93
+ if (min_value .compareTo (ele ) > 0 ) {
94
94
min_value = ele ;
95
95
}
96
96
}
@@ -201,30 +201,22 @@ public static int uglyNumber(int index) {
201
201
while (cur_index < index ) {
202
202
ugly_numbers [cur_index ] = min (ugly_numbers [multiply2_index ] * 2 , ugly_numbers [multiply3_index ] * 3 , ugly_numbers [multiply5_index ] * 5 );
203
203
204
- System .out .println ("************************" );
205
- while (ugly_numbers [multiply2_index ] * 2 < ugly_numbers [cur_index ]) {
204
+ while (ugly_numbers [multiply2_index ] * 2 <= ugly_numbers [cur_index ]) {
206
205
multiply2_index ++;
207
206
}
208
207
209
208
210
- while (ugly_numbers [multiply3_index ] * 3 < ugly_numbers [cur_index ]) {
209
+ while (ugly_numbers [multiply3_index ] * 3 <= ugly_numbers [cur_index ]) {
211
210
multiply3_index ++;
212
211
}
213
212
214
- while (ugly_numbers [multiply5_index ] * 5 < ugly_numbers [cur_index ]) {
213
+ while (ugly_numbers [multiply5_index ] * 5 <= ugly_numbers [cur_index ]) {
215
214
multiply5_index ++;
216
215
}
217
216
218
- System .out .println (ugly_numbers [multiply2_index ]);
219
- System .out .println (ugly_numbers [multiply3_index ]);
220
- System .out .println (ugly_numbers [multiply5_index ]);
221
- System .out .println ();
222
- System .out .println ();
223
-
224
217
cur_index ++;
225
218
}
226
- return ugly_numbers [index ];
227
-
219
+ return ugly_numbers [index - 1 ];
228
220
}
229
221
230
222
public int closestBig (int origion ) {
Original file line number Diff line number Diff line change @@ -65,7 +65,13 @@ public static boolean uniqueChar(String s) {
65
65
return true ;
66
66
}
67
67
68
- public static boolean permutation (String s1 , String s2 ) {
68
+ /**
69
+ * 判断是不是变位词。
70
+ * @param s1
71
+ * @param s2
72
+ * @return
73
+ */
74
+ public static boolean isPermutation (String s1 , String s2 ) {
69
75
if (s1 == null && s2 == null ) {
70
76
return true ;
71
77
} else if (s1 == null || s2 == null ) {
Original file line number Diff line number Diff line change @@ -22,14 +22,14 @@ public void testDiff() {
22
22
23
23
@ Test
24
24
public void testPermutation () {
25
- assertTrue (StringUntil .permutation ("I am a chinese" , "eseinch a ma I" ));
26
- assertFalse (StringUntil .permutation ("I am a chinese" , "esainch a ma I" ));
25
+ assertTrue (StringUntil .isPermutation ("I am a chinese" , "eseinch a ma I" ));
26
+ assertFalse (StringUntil .isPermutation ("I am a chinese" , "esainch a ma I" ));
27
27
}
28
28
29
29
@ Test
30
30
public void testQuickPermutation () {
31
- assertTrue (StringUntil .permutation ("I am a chinese" , "eseinch a ma I" ));
32
- assertFalse (StringUntil .permutation ("I am a chinese" , "esainch a ma I" ));
31
+ assertTrue (StringUntil .isPermutation ("I am a chinese" , "eseinch a ma I" ));
32
+ assertFalse (StringUntil .isPermutation ("I am a chinese" , "esainch a ma I" ));
33
33
}
34
34
35
35
@ Test
You can’t perform that action at this time.
0 commit comments