problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::smallest_value_of_the_rearranged_number::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static long long smallestNumber (long long num)
 

详细描述

在文件 leetcode.h964 行定义.

成员函数说明

◆ smallestNumber()

long long leetcode::smallest_value_of_the_rearranged_number::Solution::smallestNumber ( long long  num)
static

在文件 leetcode.cpp2416 行定义.

2416 {
2417 bool positive = num > 0;
2418 auto oss = ostringstream();
2419 num = abs(num);
2420 oss << num;
2421 vector<int> n;
2422 for(char ch: oss.str()) {
2423 n.push_back(ch - '0');
2424 }
2425 sort(n.begin(), n.end());
2426 vector<int> ans;
2427 if(positive) {
2428 for(auto i: n) {
2429 if(i != 0) {
2430 ans.push_back(i);
2431 }
2432 }
2433 for(auto i: n) {
2434 if(i == 0) {
2435 ans.insert(ans.begin() + 1, i);
2436 }
2437 }
2438 } else {
2439 for(int i = n.size() - 1; i >= 0; i--) {
2440 ans.push_back(n[i]);
2441 }
2442 }
2443 oss = ostringstream();
2444 if(!positive) {
2445 oss << '-';
2446 }
2447 for(auto i: ans) {
2448 oss << i;
2449 }
2450 auto iss = istringstream(oss.str());
2451 long long a;
2452 iss >> a;
2453 return a;
2454 }

被这些函数引用 leetcode::smallest_value_of_the_rearranged_number::TEST().


该类的文档由以下文件生成: