Created
March 18, 2023 17:05
-
-
Save mdfaizulislam/ade565b61c262a2219039b622353c54d to your computer and use it in GitHub Desktop.
Md Faizul Islam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SolutionA { | |
public solve(nums: number[]): number[] { | |
let nonzeros: number[] = []; | |
for (let i = 0; i < nums.length; i += 1) { | |
if (nums[i]) { | |
nonzeros.push(nums[i]); | |
} | |
} | |
let remaining = nums.length - nonzeros.length; | |
for (let i = 0; i < remaining; i += 1) { | |
nonzeros.push(0); | |
} | |
return nonzeros; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SolutionB { | |
public solve(n: number): number[] { | |
let answers: any[] = []; | |
for (let i: number = 1; i <= n; i += 1) { | |
if (i % 3 == 0 && i % 5 == 0) { | |
answers.push("Airwrk"); | |
} else if (i % 3 == 0) { | |
answers.push("Air"); | |
} else if (i % 5 == 0) { | |
answers.push("wrk"); | |
} else { | |
answers.push(i.toString()); | |
} | |
} | |
return answers; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <queue> | |
#include <vector> | |
#include <map> | |
#include <unordered_map> | |
// #include <bits/stdc++.h> | |
using namespace std; | |
int reverse_digit(int n) { | |
int rev = 0; | |
int d; | |
while (n) { | |
d = n % 10; | |
n /= 10; | |
rev = rev*10 + d; | |
} | |
return rev; | |
} | |
int solve(vector<int> nums) { | |
int length = nums.size(); | |
for(int i = 0; i < length; i += 1) { | |
int n = nums[i]; | |
nums.push_back(reverse_digit(n)); | |
} | |
unordered_map<int, bool> map; | |
int count = 0; | |
for(int i = 0; i < nums.size(); i += 1) { | |
if (map[nums[i]]) { | |
continue; | |
} else { | |
map[nums[i]] = true; | |
count += 1; | |
} | |
} | |
return count; | |
} | |
int main() { | |
int arr[] = { 2,3}; | |
int n = sizeof(arr) / sizeof(arr[0]); | |
vector<int> vect(arr, arr + n); | |
cout << solve(vect) << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment