I wish this helpful for you For the input [9,8,7,6,5,4,3,2,1,0], the value of n after this code: code :
float n = 0;
for(int i = 0; i < digits.length; i++) {
n = n*10 + digits[i];
}
n++;
public int[] plusOne(int[] digits) {
for (int i = digits.length  1; i >= 0; i) {
digits[i]++;
if (digits[i] < 10) {
return digits;
}
digits[i] = 0;
}
int[] result = new int[digits.length + 1];
System.arraycopy(digits, 0, result, 1, digits.length);
result[0] = 1;
return result;
}
Share :

Increment number stored as array of digitcounters
By : user3088787
Date : March 29 2020, 07:55 AM
should help you out No, this representation by itself would be useless because it fails to encode digit position, leading to many numbers having the same representation (e.g. 121 and 211). Either use a bignum library, or 80bits worth of raw binary (that being sufficient to store your declared range of 10e23)

How to generate all ndigit number in the ndigitarray way?
By : Atlantic
Date : March 29 2020, 07:55 AM
Hope that helps There is no reason to limit ourselves to the range 0  9 for each digit of the number. For each numerical place, we'll represent a range: code :
std::pair<int,int> range;
std::vector<std::pair<int, int>> ranges;
//header
class Range_Combinator {
public:
Range_Combinator(std::vector<std::pair<int, int>> const &ranges_in);
std::vector<int> Next();
std::vector<int> Current();
bool Done();
private:
bool Adjust();
void Reset_From_Current_Back(int from);
std::vector<std::pair<int, int>> ranges;
int current;
int last;
bool all_exausted;
std::vector<int> current_vals;
};
//source
Range_Combinator::Range_Combinator(
std::vector<std::pair<int, int>> const &ranges_in) {
ranges = ranges_in;
last = ranges.size()  1;
current = last;
all_exausted = false;
for (auto it : ranges) {
current_vals.push_back(it.first);
}
}
std::vector<int> Range_Combinator::Next() {
all_exausted = Adjust();
return current_vals;
}
std::vector<int> Range_Combinator::Current() { return current_vals; }
bool Range_Combinator::Done() { return all_exausted; }
bool Range_Combinator::Adjust() {
if (current_vals[current] < ranges[current].second) {
current_vals[current]++;
} else {
while (current_vals[current] == ranges[current].second) {
current;
}
if (current < 0) {
return true;
}
Reset_From_Current_Back(current + 1);
current_vals[current]++;
current = last;
}
return false;
}
void Range_Combinator::Reset_From_Current_Back(int from) {
for (int i = from; i <= last; ++i) {
current_vals[i] = ranges[i].first;
}
}
//create range combinator
std::vector<std::pair<int,int>> ranges{{1,2},{3,4}};
Range_Combinator r(ranges);
//print each number
auto number = r.Current();
while (!r.Done()){
for (auto it: number) std::cout << it; std::cout << '\n';
number = r.Next();
}
//prints: 13
// 14
// 23
// 24

SQL Server  Return All possible combinations of a 4 digit number passed to a stored procedure
By : Zeeshan
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Improving @GordonLinoff's answer, you can add an additional column in you CTE so that you can only make sure that each number is only used once: code :
declare @num varchar(max);
set @num = '1234';
with numCTE as (
select SUBSTRING(@num, 1,1) as col, 1 as cnt union
select SUBSTRING(@num, 2,1) as col, 3 as cnt union
select SUBSTRING(@num, 3,1) as col, 9 as cnt union
select SUBSTRING(@num, 4,1) as col, 27 as cnt
)
select DISTINCT (a1.col+a2.col+a3.col+a4.col)
from numCTE a1
cross join numCTE a2
cross join numCTE a3
cross join numCTE a4
where a1.cnt + a2.cnt + a3.cnt + a4.cnt = 40

In phone number validation 9,10,14 digit numbers should be valid,if number start with + then any digit number should be
By : Ham
Date : March 29 2020, 07:55 AM
To fix this issue In my phone number validation i need to validate only 9,10,14 digit numbers and 11,12,13 numbers are not valid,if phone number start with + then any digit number should be valid.Any preg_match code available? please help. :( , You can try this : code :
preg_match('/(?=^\d{9,10}$)(?=^\d{14}$)(?=^\+\d*)/', '+123456789012', $matches);
print_r($matches);

Why this code error when entering a 4*x symbol number or more? Converting a 16 digit number into 10 digit number
By : user3474080
Date : March 29 2020, 07:55 AM
it helps some times i should start at 0, not 1. You haven't noticed it yet but your math is wrong for digits 0 through 9.

