A title leetcode 168 & 171:
A, B, C, ..., Z, AA, AB, ..., AZ, BA, ..., ZZZ, AAAA .... find the i-th string
string solve(int num) {
string ans;
while(num--) { // 将0~25映射到‘A’~‘Z’
int val = num%26;
ans += 'A'+val;
num /= 26;
}
reverse(ans.begin(), ans.end());
return ans;
}
Title two
A known array size is N, the array b seek
B [I] = A [0] A [. 1] ... A [I. 1- A [I +. 1] ... A [. 1-N]
O (n-) time complexity, O (1) space complexity degree.
It requires removal cycle used i, no additional variables other memory.
void solve(int *a, int *b, int N) {
int i;
b[0] = 1;
for(i = 1 ; i < N; i++)
b[i] = b[i-1]*a[i-1];
b[0] = a[--i];
for(--i; i > 0; i--) {
b[i] *= b[0];
b[0] *= a[i];
}
}