File tree Expand file tree Collapse file tree
src/main/java/com/fancv/leetCode Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .fancv .leetCode .LinkedList ;
2+
3+ public class deleteDuplicatesOne {
4+
5+ public static void main (String [] args ) {
6+ ListNode a = new ListNode (4 , null );
7+ ListNode b = new ListNode (2 , a );
8+ ListNode c = new ListNode (2 , b );
9+ ListNode d = new ListNode (2 , c );
10+ ListNode e = new ListNode (1 , d );
11+
12+ ListNode result = deleteDuplicates (e );
13+ System .out .println (result .val );
14+ }
15+
16+
17+ /**
18+ * 删除链表中重复元素 回调
19+ * 1 1 2 3 3
20+ *
21+ * @param head
22+ * @return
23+ */
24+ public static ListNode deleteDuplicates (ListNode head ) {
25+ if (head == null || head .next == null ) {
26+ return head ;
27+ }
28+ ListNode sail = head .next ;
29+ if (head .val == sail .val ) {
30+ while (sail != null && head .val == sail .val ) {
31+ sail = sail .next ;
32+ }
33+ }
34+ head .next = deleteDuplicates (sail );
35+
36+ return head ;
37+ }
38+
39+ }
Original file line number Diff line number Diff line change 1+ package com .fancv .leetCode .mathematics ;
2+
3+ import java .util .Arrays ;
4+
5+ /**
6+ * @author hamish-wu
7+ */
8+ public class MathArray {
9+
10+
11+ public static void main (String [] args ) {
12+
13+ }
14+
15+ public int maximumGap (int [] nums ) {
16+
17+ //1.排序
18+ Arrays .sort (nums );
19+
20+ //2.遍历元素,计算相邻元素差值 最大
21+
22+
23+
24+ return 0 ;
25+ }
26+
27+ }
Original file line number Diff line number Diff line change 66public class MyMathematics {
77
88 public static void main (String [] args ) {
9- System .out .println (isUgly (0 ));
10- System .out .println (isUgly (2 ));
11- System .out .println (isUgly (1024 ));
12- System .out .println (isUgly (14 ));
9+ System .out .println (nthUglyNumber (400 ));
10+ System .out .println (nthUglyNumber (800 ));
11+ System .out .println (nthUglyNumber (1200 ));
12+ System .out .println (nthUglyNumber (1600 ));
13+ System .out .println (nthUglyNumber (200 ));
1314 }
1415
1516 public static int [] findErrorNums (int [] nums ) {
@@ -63,7 +64,7 @@ public static boolean threeConsecutiveOdds(int[] arr) {
6364 */
6465 public static boolean isUgly (int n ) {
6566 boolean r = false ;
66- if ( n == 0 ) {
67+ if ( n == 0 ) {
6768 return r ;
6869 }
6970 //1.偶数
@@ -97,6 +98,82 @@ else if (n % 3 == 0) {
9798 r = true ;
9899 }
99100 return r ;
101+ }
102+
103+ /**
104+ * 丑数,数字 2 3 5 乘积
105+ *
106+ * @param n
107+ * @return
108+ */
109+ public boolean isUgly2 (int n ) {
110+ boolean r = false ;
111+ //1.偶数
112+ while (n % 2 == 0 ) {
113+ n = n / 2 ;
114+ }
115+ //2.奇数 3的倍数
116+ while (n % 3 == 0 ) {
117+ n = n / 3 ;
118+ }
119+ while (n % 5 == 0 ) {
120+ n = n / 5 ;
121+ }
122+ if (n == 1 ) {
123+ r = true ;
124+ }
125+ return r ;
126+ }
127+
128+ /**
129+ * 第N 个丑数 笨办法
130+ *
131+ * @param n
132+ * @return
133+ */
134+ public static int nthUglyNumber (int n ) {
135+ int i = 1 ;
136+ int temp = 0 ;
137+ if (n > 200 ) {
138+ i = 16200 ;
139+ temp = 199 ;
140+ } else if (n > 400 ) {
141+ i = 311040 ;
142+ temp = 399 ;
143+ } else if (n > 800 ) {
144+ i = 12754584 ;
145+ temp = 799 ;
146+ } else if (n > 1200 ) {
147+ i = 174960000 ;
148+ temp = 799 ;
149+ } else if (n > 1600 ) {
150+ i = 1399680000 ;
151+ temp = 1599 ;
152+ }
153+ for (; i < Integer .MAX_VALUE ; i ++) {
154+ if (isUgly (i )) {
155+ temp ++;
156+ }
157+ if (temp == n ) {
158+ return i ;
159+ }
160+ }
161+ return 0 ;
162+ }
163+
164+ /**
165+ * 第N 个丑数 三指针算法
166+ *
167+ * @param n
168+ * @return
169+ */
170+ public static int nthUglyNumber2 (int n ) {
171+
172+
173+
174+
175+
100176
177+ return 0 ;
101178 }
102179}
You can’t perform that action at this time.
0 commit comments