Skip to content

Commit ad803ac

Browse files
committed
Improved dart tasks
1 parent 70ade88 commit ad803ac

File tree

7 files changed

+14
-18
lines changed
  • src/main/dart
    • g0001_0100
    • g0101_0200

7 files changed

+14
-18
lines changed

src/main/dart/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class Solution {
5353
int start = 0;
5454
5555
for (int i = 0; i < s.length; i++) {
56-
int cur = s.codeUnitAt(i); // Getting ASCII value of the character
56+
// Getting ASCII value of the character
57+
int cur = s.codeUnitAt(i);
5758
if (lastIndices[cur] < start) {
5859
lastIndices[cur] = i;
5960
curLen++;

src/main/dart/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class Solution {
6868
int low = 0;
6969
int high = n1;
7070
71-
int minValue = -pow(2, 31).toInt(); // substitute for Integer.MIN_VALUE
72-
int maxValue = pow(2, 31).toInt() - 1; // substitute for Integer.MAX_VALUE
71+
// substitute for Integer.MIN_VALUE
72+
int minValue = -pow(2, 31).toInt();
73+
// substitute for Integer.MAX_VALUE
74+
int maxValue = pow(2, 31).toInt() - 1;
7375
7476
while (low <= high) {
7577
int cut1 = (low + high) ~/ 2;

src/main/dart/g0001_0100/s0008_string_to_integer_atoi/readme.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,14 @@ class Solution {
149149
// read digits
150150
while (current < s.length && digits.containsKey(s[current])) {
151151
int digit = digits[s[current++]]!;
152-
// check owerflow
152+
// check overflow
153153
if (sign == -1 && res < (MIN + digit) / 10) {
154154
return MIN;
155155
} else if (res > (MAX - digit) / 10) {
156156
return MAX;
157157
}
158-
159158
res = res * 10 + sign * digit;
160159
}
161-
162160
return res;
163161
}
164162
}

src/main/dart/g0001_0100/s0011_container_with_most_water/readme.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Given `n` non-negative integers <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n
4646
## Solution
4747

4848
```dart
49+
import 'dart:math';
50+
4951
class Solution {
5052
int maxArea(List<int> height) {
5153
int maxArea = -1;
@@ -64,9 +66,5 @@ class Solution {
6466
6567
return maxArea;
6668
}
67-
68-
int max(int a, int b) {
69-
return (a > b) ? a : b;
70-
}
7169
}
7270
```

src/main/dart/g0001_0100/s0045_jump_game_ii/readme.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ You can assume that you can always reach the last index.
3535
## Solution
3636

3737
```dart
38+
import 'dart:math';
39+
3840
class Solution {
3941
int jump(List<int> nums) {
4042
int length = 0;
@@ -58,10 +60,5 @@ class Solution {
5860
5961
return minJump;
6062
}
61-
62-
// Dart's equivalent for Java's Math.max() is the built-in max() function
63-
int max(int a, int b) {
64-
return a > b ? a : b;
65-
}
6663
}
6764
```

src/main/dart/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Note that buying on day 2 and selling on day 1 is not allowed because you must b
3737
## Solution
3838

3939
```dart
40+
import 'dart:math';
41+
4042
class Solution {
4143
int maxProfit(List<int> prices) {
4244
int maxProfit = 0;
@@ -52,7 +54,5 @@ class Solution {
5254
5355
return maxProfit;
5456
}
55-
56-
int max(int a, int b) => a > b ? a : b; // Utility function for max
5757
}
5858
```

src/main/dart/g0101_0200/s0124_binary_tree_maximum_path_sum/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Given the `root` of a binary tree, return _the maximum **path sum** of any **non
4949
* }
5050
*/
5151
class Solution {
52-
int _max = -999999999; // Use a large negative value instead of -double.infinity.toInt()
52+
int _max = -999999999;
5353
5454
int _helper(TreeNode? root) {
5555
if (root == null) {

0 commit comments

Comments
 (0)