[问答题]

```class Solution:
def sort_number_str(self, s):
if not s:
return s
s_lst = list(map(int, list(s)))
self.quit_sort(s_lst, 0, len(s_lst) - 1)
return ''.join([str(i) for i in s_lst if i > 0])

def quit_sort(self, lst, left, right):
def find_index(lst, left, right):
tmp = lst[left]
while left < right:
while left < right and lst[right] >= tmp:
right -= 1
lst[left] = lst[right]
while left < right and lst[left] <= tmp:
left += 1
lst[right] = lst[left]
lst[left] = tmp
return left

if left < right:
index = find_index(lst, left, right)
self.quit_sort(lst, left, index - 1)
self.quit_sort(lst, index + 1, right)```

java 语言:
```@Test
public void test8(){
String a = "1207653";
char[] charArray = a.replaceAll("0", "").toCharArray();
Arrays.sort(charArray);
System.out.println(new String(charArray));
}```

var num="9002";
function stringchange(num){
var pattern=/[0]*/g;
num=num.replace(pattern,"");
num=num.split("");
num.sort(function(a,b){
return a-b;
});
console.log(num.join(""));
}

`stringchange(num);`

```//采用优先队列 重载为升序排列
typedef priority_queue<char,vector<char >,greater<char> > pq;
pq slove()
{
string str = "900142";
priority_queue<char,vector<char >,greater<char> > que;
int len = str.size();
//不将字符0 插入队列
for(int i = 0;i < len;i++)
{
if(str[i] >= '1' && str[i] <= '9')
{
que.push(str[i]);
}
}
//测试输出
while(!que.empty())
{
cout << que.top() << endl;
que.pop();
}
return que;
}
```

void strSort(char *str){
if (NULL == str) return;
int map[9];
int n = strlen(str);
for (int i = 0; i < 9; ++i){
map[i] = 0;
}
for (int i = 0; i < n; ++i){
if (str[i] >= '1' && str[i] <= '9') ++map[str[i] - '1'];
}
int j = 0;
for (int i = 0; i < 9; ++i){
while (map[i] > 0){
str[j++] = i + '1';
--map[i];
}
}
str[j] = '\0';
}

function sortFn(str){
return str.replace(/0/g,"").split("").sort().join("");
}

```def remove_string_0(str):
return ''.join(sorted([i for i in str if i != '0']))```

``` def removeString0(str_str):
tempStr=[]
print(str_str)
for i in range(len(str_str)):
tempStr.append(int(str_str[i]))
tempStr=sorted(tempStr)
Str=[]
for index in range(len(tempStr)):
if tempStr[index]!=0:
Str.append(tempStr[index])
print(Str)```

8条回答 11156浏览

# 相关试题

• 扫描二维码，关注牛客网

• 下载牛客APP，随时随地刷题