Skip to content

Improved tasks 2678, 2679, 2706, 2703, 2711 #1923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package g2601_2700.s2678_number_of_senior_citizens;

// #Easy #Array #String #2023_09_11_Time_0_ms_(100.00%)_Space_40.7_MB_(97.65%)
// #Easy #Array #String #2025_02_26_Time_0_ms_(100.00%)_Space_42.10_MB_(95.99%)

public class Solution {
public int countSeniors(String[] details) {
int count = 0;
int seniorCitizen = 0;
for (String detail : details) {
if (((detail.charAt(11) - '0' == 6) && (detail.charAt(12) - '0' > 0))
|| (detail.charAt(11) - '0' > 6)) {
count++;
int age = (detail.charAt(11) - '0') * 10 + detail.charAt(12) - '0';
if (age > 60) {
seniorCitizen++;
}
}
return count;
return seniorCitizen;
}
}
3 changes: 0 additions & 3 deletions src/main/java/g2601_2700/s2679_sum_in_a_matrix/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@
public class Solution {
public int matrixSum(int[][] nums) {
int result = 0;

for (int[] row : nums) {
Arrays.sort(row);
reverseArray(row);
}

for (int i = 0; i < nums[0].length; i++) {
int max = 0;
for (int[] num : nums) {
max = Math.max(max, num[i]);
}
result += max;
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// #Easy #2023_09_14_Time_49_ms_(86.01%)_Space_42.9_MB_(39.39%)
// #Easy #2025_02_26_Time_50_ms_(82.03%)_Space_54.95_MB_(7.19%)

function argumentsLength(...args: any[]): number {
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };

function argumentsLength(...args: JSONValue[]): number {
return args.length
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class Solution {
public int buyChoco(int[] prices, int money) {
int minPrice1 = Integer.MAX_VALUE;
int minPrice2 = Integer.MAX_VALUE;

for (int price : prices) {
if (price < minPrice1) {
minPrice2 = minPrice1;
Expand All @@ -15,9 +14,7 @@ public int buyChoco(int[] prices, int money) {
minPrice2 = price;
}
}

int totalPrice = minPrice1 + minPrice2;

if (totalPrice > money) {
return money;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
int n = grid[0].length;
int[][] arrTopLeft = new int[m][n];
int[][] arrBotRight = new int[m][n];

for (int i = m - 1; i >= 0; i--) {
int c = 0;
int r = i;
Expand All @@ -21,7 +20,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r++][c++]);
}
}

for (int i = 1; i < n; i++) {
int r = 0;
int c = i;
Expand All @@ -31,7 +29,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r++][c++]);
}
}

for (int i = 0; i < n; i++) {
int r = m - 1;
int c = i;
Expand All @@ -41,7 +38,6 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r--][c--]);
}
}

for (int i = m - 1; i >= 0; i--) {
int c = n - 1;
int r = i;
Expand All @@ -51,14 +47,12 @@ public int[][] differenceOfDistinctValues(int[][] grid) {
set.add(grid[r--][c--]);
}
}

int[][] result = new int[m][n];
for (int r = 0; r < m; r++) {
for (int c = 0; c < n; c++) {
result[r][c] = Math.abs(arrTopLeft[r][c] - arrBotRight[r][c]);
}
}

return result;
}

Expand Down