Skip to content

Commit

Permalink
剑指offer部分
Browse files Browse the repository at this point in the history
  • Loading branch information
versionwen committed Sep 27, 2019
1 parent cc22fcc commit 3575c18
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 45 deletions.
92 changes: 49 additions & 43 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main/java/com/offer/Offer32.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public static String PrintMinNumber(int[] numbers){
}
StringBuffer res=new StringBuffer();
String[] str=new String[len];
for(int i=0;i<len;i++){
for(int i=0;i<len;i++){//改成字符串数组
str[i]=String.valueOf(numbers[i]);
}
Arrays.sort(str, new Comparator<String>() {
Arrays.sort(str, new Comparator<String>() {//重写比较方法
@Override
public int compare(String o1, String o2) {//ab>ba,a>b
String c1=o1+o2;//ab<ba,a<b
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/offer/Offer33.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.offer;

public class Offer33 {
public static int GetUglyNumber_Solution(int index){
if(index<=0){
return 0;
}
if(index==1){
return 1;
}
int t2=0,t3=0,t5=0;
int[]res=new int[index];
res[0]=1;
for(int i=1;i<index;i++){
res[i]=Math.min(res[t2]*2,Math.min(res[t3]*3,res[t5]*5));
if(res[i]==res[t2]*2){
t2++;
}
if(res[i]==res[t3]*3){
t3++;
}
if(res[i]==res[t5]*5){
t5++;
}
}
return res[index-1];
}

public static void main(String[] args) {
System.out.println(GetUglyNumber_Solution(7));
}
}

0 comments on commit 3575c18

Please sign in to comment.