Skip to content

Commit

Permalink
Improved dart tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed Oct 13, 2024
1 parent ceea62c commit 9aede6e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Solution {
int start = 0;

for (int i = 0; i < s.length; i++) {
int cur = s.codeUnitAt(i); // Getting ASCII value of the character
// Getting ASCII value of the character
int cur = s.codeUnitAt(i);
if (lastIndices[cur] < start) {
lastIndices[cur] = i;
curLen++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class Solution {
int low = 0;
int high = n1;

int minValue = -pow(2, 31).toInt(); // substitute for Integer.MIN_VALUE
int maxValue = pow(2, 31).toInt() - 1; // substitute for Integer.MAX_VALUE
// substitute for Integer.MIN_VALUE
int minValue = -pow(2, 31).toInt();
// substitute for Integer.MAX_VALUE
int maxValue = pow(2, 31).toInt() - 1;

while (low <= high) {
int cut1 = (low + high) ~/ 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ class Solution {
// read digits
while (current < s.length && digits.containsKey(s[current])) {
int digit = digits[s[current++]]!;
// check owerflow
// check overflow
if (sign == -1 && res < (MIN + digit) / 10) {
return MIN;
} else if (res > (MAX - digit) / 10) {
return MAX;
}

res = res * 10 + sign * digit;
}

return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1)
// #2024_09_30_Time_337_ms_(96.77%)_Space_172.5_MB_(64.52%)

import 'dart:math';

class Solution {
int maxArea(List<int> height) {
int maxArea = -1;
Expand All @@ -20,8 +22,4 @@ class Solution {

return maxArea;
}

int max(int a, int b) {
return (a > b) ? a : b;
}
}
7 changes: 2 additions & 5 deletions src/main/dart/g0001_0100/s0045_jump_game_ii/Solution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_4
// #Big_O_Time_O(n)_Space_O(1) #2024_10_04_Time_335_ms_(81.58%)_Space_148.6_MB_(76.32%)

import 'dart:math';

class Solution {
int jump(List<int> nums) {
int length = 0;
Expand All @@ -25,9 +27,4 @@ class Solution {

return minJump;
}

// Dart's equivalent for Java's Math.max() is the built-in max() function
int max(int a, int b) {
return a > b ? a : b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// #Data_Structure_I_Day_3_Array #Dynamic_Programming_I_Day_7 #Level_1_Day_5_Greedy #Udemy_Arrays
// #Big_O_Time_O(N)_Space_O(1) #2024_10_07_Time_374_ms_(89.33%)_Space_190.1_MB_(48.33%)

import 'dart:math';

class Solution {
int maxProfit(List<int> prices) {
int maxProfit = 0;
Expand All @@ -17,6 +19,4 @@ class Solution {

return maxProfit;
}

int max(int a, int b) => a > b ? a : b; // Utility function for max
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* }
*/
class Solution {
int _max = -999999999; // Use a large negative value instead of -double.infinity.toInt()
int _max = -999999999;

int _helper(TreeNode? root) {
if (root == null) {
Expand Down

0 comments on commit 9aede6e

Please sign in to comment.