Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Task1/Java/Problem1.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
**/

public class Solution {
public boolean isPalindrome(int y) {
public boolean isPalindrome(int x) {
if (x < 0) {
return true;
return false;
}
int reversedNumber = 0;
int originalNumber = x;
while (x > 0) {
int digit = x % 10;
x = x / 10;
reversedNumber == reversedNumber * 10 + digit;
reversedNumber = reversedNumber * 10 + digit;
}

return originalNumber = reversedNumber;
    }
}
return originalNumber == reversedNumber;
}
}
17 changes: 10 additions & 7 deletions Task2/Java/Problem2.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
import java.util.Arrays;

public class Solution {
public int() plusOne(int() digit) {
int n = digits.length;
public int[] plusOne(int[] digit) {
int n = digit.length;

// Traverse the digits array from right to left
for (Int i = n - 1, i >= 0; i--) {
for (int i = n - 1, i >= 0; i--) {
// If the current digit is less than 9, simply increment it and return the array
if (digit[i] < 9) {
digits[i]++
return digits;
digit[i]++
return digit;
} else {
// If the current digit is 9, set it to 0 and continue the loop
digit[i] = 0;
Expand All @@ -55,6 +55,9 @@ public int() plusOne(int() digit) {
// If all digits were 9, we need to create a new array with an extra digit at the beginning
int[] result = new int[n + 1];
result[0] = 1; // Set the most significant digit to 1
return result;
    }
for(int i=1;i<result.length;i++){
result[i]=digit[i-1];
}
return result;
}
}
14 changes: 8 additions & 6 deletions Task3/Java/Problem3.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ Come up with an algorithm that is less than O(n2) time complexity.
class Solution {
public int[] twoSum(int[] nums, int target) {
int n = nums.length;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}

int a=0;
for (int i = 1; i < n ; i++) {

if(nums[i-1]+nums[i]==target){
int [] ans=[i-1,i];
return ans;
}
}
return new int[]{}; // No solution found
return new int[]; // No solution found
}
}