# 剑指offer第八天

### 32.把数组排成最小的数

#### 解题思路：

1. 实际是将数组元素进行排序的操作
2. 排序规则为，若MN组成的数字大于NM，则N在前M在后
3. 使用Comparatpr定制排序规则
4. 考虑到数字连接起来可能使int溢出，所以转换为使用String来操作。
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class Solution {
public String PrintMinNumber(int [] numbers) {
String result = "";
if(numbers == null || numbers.length == 0) return result;
ArrayList<String> list = new ArrayList<>();
for(int i = 0 ;i < numbers.length;i++){
}
Collections.sort(list,new Comparator<String>(){
@Override
public int compare(String sNum1,String sNum2){
String num1 = sNum1+sNum2;
String num2 = sNum2+sNum1;
return num1.compareTo(num2);
}
});
for(String str : list){
result += str;
}
return result;
}
}


### 33.丑数

public class Solution {
public int GetUglyNumber_Solution(int index) {
if(index <= 0 ) return 0;
int mult2_Idx = 0,mult3_Idx = 0,mult5_Idx = 0;
int[] uglyNumber = new int[index];
uglyNumber[0] = 1;
for(int i = 1;i<index;i++){
int min = Math.min(Math.min(uglyNumber[mult2_Idx]*2,
uglyNumber[mult3_Idx]*3),
uglyNumber[mult5_Idx]*5);
uglyNumber[i] = min;
while(uglyNumber[mult2_Idx]*2 <= uglyNumber[i])
mult2_Idx++;
while(uglyNumber[mult3_Idx]*3 <= uglyNumber[i])
mult3_Idx++;
while(uglyNumber[mult5_Idx]*5 <= uglyNumber[i])
mult5_Idx++;
}
return uglyNumber[index-1];
}
}


### 34.第一个只出现一次的字符

import java.util.HashMap;
public class Solution {
public int FirstNotRepeatingChar(String str) {
int result = Integer.MAX_VALUE;
if(str.length() == 0) return -1;
HashMap<Character,Integer> charIdx = new HashMap<>();
for(int i = 0 ;i < str.length(); i++){
Character c = str.charAt(i);
if(charIdx.containsKey(c)){
charIdx.put(c,-1);
}else{
charIdx.put(c,i);
}
}
for(int index : charIdx.values()){
if(index != -1){
result = Math.min(result,index);
}
}
return result;
}
}


06-02 1992

08-05 1万+

08-16 3万+

08-29 1119

08-18 3324

02-03 3万+

07-20 378

03-13 232

04-06 2万+

05-01 1327

03-19 500

09-02 554

05-04 8744

11-24 176

08-07 4万+

06-01 1201

09-17 7万+

07-14 49

04-14 59万+

03-13 15万+

03-04 14万+

03-08 2万+

04-25 6万+

03-10 13万+

03-10 18万+

03-12 11万+

03-13 11万+

03-18 9928

03-19 8万+

03-19 3万+

03-22 4万+

03-23 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-29 21万+

03-29 10万+

03-30 16万+

04-02 1万+

04-02 5708

04-02 4万+

04-06 1万+

04-06 7万+

04-09 8万+

04-09 2万+

05-17 8578

04-11 3万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

05-01 6437

05-03 1万+

05-16 5万+

05-06 1万+

05-07 2776

05-07 1万+

05-08 4万+

05-10 3322

05-14 6540

05-16 3605

05-16 1万+

05-17 5088

05-30 399

05-20 1012

05-18 2261

05-18 8441

05-27 1453

05-18 3624

05-28 1302

05-19 1万+

05-19 1946

05-21 7623

05-21 7654

05-27 5216

05-25 5399

05-23 6564

#### 2020年，令人惊叹的Echarts！

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客