https://www.codecademy.com/profiles/cloudJumper07218/certificates/e72695d81eb54c9f94ed5d31426b29cc
Category Archives: Computer Science
Intro to Generative AI Course – Codecademy
Learn How to Use ChatGPT Course – Codecademy
AI for Coding Course – Codecademy
Nintex Certified Expert
ExpressJS certificate from Codecademy
NodeJS Certificate from Codecademy
1281. Subtract the Product and Sum of Digits of an Integer
1281. Subtract the Product and Sum of Digits of an Integer
class Solution {
public int subtractProductAndSum(int n) {
ArrayList<Integer> list = new ArrayList<Integer>();
while(n != 0){
list.add(n%10);
n = n/10;
}
int product = 1;
int sum = 0;
for(int i = 0; i < list.size(); i++){
product *= list.get(i);
sum+= list.get(i);
}
return product - sum;
}
}
896. Monotonic Array
class Solution {
public boolean isMonotonic(int[] nums) {
boolean increasing = true;
boolean decreasing = true;
for(int i = 1; i < nums.length; i++){
if(nums[i]< nums[i-1]) {
increasing = false;
break;
}
}
for( int i = 1; i < nums.length; i++){
if(nums[i]> nums[i-1]){
decreasing = false;
break;
}
}
return increasing|decreasing;
}
}
917. Reverse Only Letters
class Solution {
public String reverseOnlyLetters(String s) {
char[] arr = s.toCharArray();
int arrIndex = getNextEmpty(arr.length,arr);
for(int i = 0 ; i < s.length(); i++){
char c = s.charAt(i);
if((c>='a' && c <='z') ||
(c>='A' && c <='Z')){
arr[arrIndex] = c;
arrIndex = getNextEmpty(arrIndex,arr);
}
}
return new String(arr);
}
public int getNextEmpty(int current, char[] arr){
for(int i = current-1; i >=0; i--){
char c = arr[i];
if((c >='a' && c <='z') ||
(c>='A' && c <='Z')) return i;
}
return 0;
}
}
