Skip to content

Commit 9b1f5b3

Browse files
authored
Merge pull request #36 from fartem/3340-Check-Balanced-String
2025-05-06 v. 1.0.7: added "3340. Check Balanced String"
2 parents 3111dc2 + bc641b7 commit 9b1f5b3

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
4141
| 263. Ugly Number | [Link](https://lettcode.com/problems/ugly-number/) | [Link](./lib/easy/263_ugly_number.dart) |
4242
| 500. Keyboard Row | [Link](https://leetcode.com/problems/keyboard-row/) | [Link](./lib/easy/500_keyboard_row.dart) |
4343
| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.dart) |
44+
| 3340. Check Balanced String | [Link](https://leetcode.com/problems/check-balanced-string/) | [Link](./lib/easy/3340_check_balanced_string.dart) |
4445
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.dart) |
4546
| 3536. Maximum Product of Two Digits | [Link](https://leetcode.com/problems/maximum-product-of-two-digits/) | [Link](./lib/easy/3536_maximum_product_of_two_digits.dart) |
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
bool isBalanced(String num) {
3+
var even = 0;
4+
var odd = 0;
5+
6+
for (var i = 0; i < num.length; i += 1) {
7+
final curr = int.parse(num[i]);
8+
9+
if (i.isEven) {
10+
even += curr;
11+
} else {
12+
odd += curr;
13+
}
14+
}
15+
16+
return even == odd;
17+
}
18+
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: leetcode_dart
22
description: Some solved problems from https://leetcode.com on Dart
3-
version: 1.0.6
3+
version: 1.0.7
44
homepage: https://github.com/fartem/leetcode-dart
55

66
environment:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:leetcode_dart/easy/3340_check_balanced_string.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group(
6+
'Example tests',
7+
() {
8+
final solution = Solution();
9+
10+
test(
11+
'false',
12+
() => expect(
13+
false,
14+
solution.isBalanced(
15+
'1234',
16+
),
17+
),
18+
);
19+
test(
20+
'true',
21+
() => expect(
22+
true,
23+
solution.isBalanced(
24+
'24123',
25+
),
26+
),
27+
);
28+
},
29+
);
30+
}

0 commit comments

Comments
 (0)