Skip to content

Commit a523c98

Browse files
committed
2025-05-01 v. 1.0.2: refactored project
1 parent c7a882c commit a523c98

File tree

68 files changed

+605
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+605
-338
lines changed

.github/workflows/dart.yml

+29-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,41 @@ on:
66
pull_request:
77
branches: [ master ]
88

9+
env:
10+
DART_VERSION: "3.7.2"
11+
912
jobs:
10-
build:
13+
analyzer:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: dart-lang/setup-dart@v1.0
18+
with:
19+
sdk: ${{ env.DART_VERSION }}
20+
- name: Install dependencies
21+
run: dart pub get
22+
- name: Run tests
23+
run: dart analyze
24+
25+
formatter:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v2
29+
- uses: dart-lang/setup-dart@v1.0
30+
with:
31+
sdk: ${{ env.DART_VERSION }}
32+
- name: Install dependencies
33+
run: dart pub get
34+
- name: Run tests
35+
run: dart format -l 120 --set-exit-if-changed ./
36+
37+
tests:
1138
runs-on: ubuntu-latest
1239
steps:
1340
- uses: actions/checkout@v2
1441
- uses: dart-lang/setup-dart@v1.0
1542
with:
16-
sdk: 3.7.2
43+
sdk: ${{ env.DART_VERSION }}
1744
- name: Install dependencies
1845
run: dart pub get
1946
- name: Run tests

README.md

+27-27
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
1212

1313
### Easy
1414

15-
| Name | Link to LeetCode | Link to solution |
16-
| ----------------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
17-
| 1. Two Sum | [Link](https://leetcode.com/problems/two-sum/) | [Link](./lib/easy/two_sum.dart) |
18-
| 9. Palindrome Number | [Link](https://leetcode.com/problems/palindrome-number/) | [Link](./lib/easy/palindrome_number.dart) |
19-
| 13. Roman to Integer | [Link](https://leetcode.com/problems/roman-to-integer/) | [Link](./lib/easy/roman_to_integer.dart) |
20-
| 14. Longest Common Prefix | [Link](https://leetcode.com/problems/longest-common-prefix/) | [Link](./lib/easy/longest_common_prefix.dart) |
21-
| 20. Valid Parentheses | [Link](https://leetcode.com/problems/valid-parentheses/) | [Link](./lib/easy/valid_parentheses.dart) |
22-
| 21. Merge Two Sorted Lists | [Link](https://leetcode.com/problems/merge-two-sorted-lists/) | [Link](./lib/easy/merge_two_sorted_lists.dart) |
23-
| 27. Remove Element | [Link](https://leetcode.com/problems/remove-element/) | [Link](./lib/easy/remove_element.dart) |
24-
| 35. Search Insert Position | [Link](https://leetcode.com/problems/search-insert-position/) | [Link](./lib/easy/search_insert_position.dart) |
25-
| 58. Length of Last Word | [Link](https://leetcode.com/problems/length-of-last-word/) | [Link](./lib/easy/length_of_last_word.dart) |
26-
| 66. Plus One | [Link](https://leetcode.com/problems/plus-one/) | [Link](./lib/easy/plus_one.dart) |
27-
| 67. Add Binary | [Link](https://leetcode.com/problems/add-binary/) | [Link](./lib/easy/add_binary.dart) |
28-
| 69. Sqrt(x) | [Link](https://leetcode.com/problems/sqrtx/) | [Link](./lib/easy/sqrt_x.dart) |
29-
| 70. Climbing Stairs | [Link](https://leetcode.com/problems/climbing-stairs/) | [Link](./lib/easy/climbing_stairs.dart) |
30-
| 83. Remove Duplicates from Sorted List | [Link](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) | [Link](./lib/easy/remove_duplicates_from_sorted_list.dart) |
31-
| 88. Merge Sorted Array | [Link](https://leetcode.com/problems/merge-sorted-array/) | [Link](./lib/easy/merge_sorted_array.dart) |
32-
| 94. Binary Tree Inorder Traversal | [Link](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Link](./lib/easy/binary_tree_inorder_traversal.dart) |
33-
| 100. Same Tree | [Link](https://leetcode.com/problems/same-tree/) | [Link](./lib/easy/same_tree.dart) |
34-
| 101. Symmetric Tree | [Link](https://leetcode.com/problems/symmetric-tree/) | [Link](./lib/easy/symmetric_tree.dart) |
35-
| 104. Maximum Depth of Binary Tree | [Link](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [Link](./lib/easy/maximum_depth_of_binary_tree.dart) |
36-
| 108. Convert Sorted Array to Binary Search Tree | [Link](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) | [Link](./lib/easy/convert_sorted_array_to_binary_search_tree.dart) |
37-
| 110. Balanced Binary Tree | [Link](https://leetcode.com/problems/balanced-binary-tree/) | [Link](./lib/easy/balanced_binary_tree.dart) |
38-
| 111. Minimum Depth of Binary Tree | [Link](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [Link](./lib/easy/minimum_depth_of_binary_tree.dart) |
39-
| 112. Path Sum | [Link](https://leetcode.com/problems/path-sum/) | [Link](./lib/easy/path_sum.dart) |
40-
| 118. Pascal's Triangle | [Link](https://leetcode.com/problems/pascals-triangle/) | [Link](./lib/easy/pascals_triangle.dart) |
41-
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/find_closest_person.dart) |
15+
| Name | Link to LeetCode | Link to solution |
16+
| ----------------------------------------------- | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
17+
| 1. Two Sum | [Link](https://leetcode.com/problems/two-sum/) | [Link](./lib/easy/1_two_sum.dart) |
18+
| 9. Palindrome Number | [Link](https://leetcode.com/problems/palindrome-number/) | [Link](./lib/easy/9_palindrome_number.dart) |
19+
| 13. Roman to Integer | [Link](https://leetcode.com/problems/roman-to-integer/) | [Link](./lib/easy/13_roman_to_integer.dart) |
20+
| 14. Longest Common Prefix | [Link](https://leetcode.com/problems/longest-common-prefix/) | [Link](./lib/easy/14_longest_common_prefix.dart) |
21+
| 20. Valid Parentheses | [Link](https://leetcode.com/problems/valid-parentheses/) | [Link](./lib/easy/20_valid_parentheses.dart) |
22+
| 21. Merge Two Sorted Lists | [Link](https://leetcode.com/problems/merge-two-sorted-lists/) | [Link](./lib/easy/21_merge_two_sorted_lists.dart) |
23+
| 27. Remove Element | [Link](https://leetcode.com/problems/remove-element/) | [Link](./lib/easy/27_remove_element.dart) |
24+
| 35. Search Insert Position | [Link](https://leetcode.com/problems/search-insert-position/) | [Link](./lib/easy/35_search_insert_position.dart) |
25+
| 58. Length of Last Word | [Link](https://leetcode.com/problems/length-of-last-word/) | [Link](./lib/easy/58_length_of_last_word.dart) |
26+
| 66. Plus One | [Link](https://leetcode.com/problems/plus-one/) | [Link](./lib/easy/66_plus_one.dart) |
27+
| 67. Add Binary | [Link](https://leetcode.com/problems/add-binary/) | [Link](./lib/easy/67_add_binary.dart) |
28+
| 69. Sqrt(x) | [Link](https://leetcode.com/problems/sqrtx/) | [Link](./lib/easy/69_sqrt_x.dart) |
29+
| 70. Climbing Stairs | [Link](https://leetcode.com/problems/climbing-stairs/) | [Link](./lib/easy/70_climbing_stairs.dart) |
30+
| 83. Remove Duplicates from Sorted List | [Link](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) | [Link](./lib/easy/83_remove_duplicates_from_sorted_list.dart) |
31+
| 88. Merge Sorted Array | [Link](https://leetcode.com/problems/merge-sorted-array/) | [Link](./lib/easy/88_merge_sorted_array.dart) |
32+
| 94. Binary Tree Inorder Traversal | [Link](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Link](./lib/easy/94_binary_tree_inorder_traversal.dart) |
33+
| 100. Same Tree | [Link](https://leetcode.com/problems/same-tree/) | [Link](./lib/easy/100_same_tree.dart) |
34+
| 101. Symmetric Tree | [Link](https://leetcode.com/problems/symmetric-tree/) | [Link](./lib/easy/101_symmetric_tree.dart) |
35+
| 104. Maximum Depth of Binary Tree | [Link](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [Link](./lib/easy/104_maximum_depth_of_binary_tree.dart) |
36+
| 108. Convert Sorted Array to Binary Search Tree | [Link](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) | [Link](./lib/easy/108_convert_sorted_array_to_binary_search_tree.dart) |
37+
| 110. Balanced Binary Tree | [Link](https://leetcode.com/problems/balanced-binary-tree/) | [Link](./lib/easy/110_balanced_binary_tree.dart) |
38+
| 111. Minimum Depth of Binary Tree | [Link](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [Link](./lib/easy/111_minimum_depth_of_binary_tree.dart) |
39+
| 112. Path Sum | [Link](https://leetcode.com/problems/path-sum/) | [Link](./lib/easy/112_path_sum.dart) |
40+
| 118. Pascal's Triangle | [Link](https://leetcode.com/problems/pascals-triangle/) | [Link](./lib/easy/118_pascals_triangle.dart) |
41+
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.dart) |

analysis_options.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: package:lints/core.yaml
2+
3+
linter:
4+
rules:
5+
file_names: false

lib/common/tree_node.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@ class TreeNode {
33
TreeNode? left;
44
TreeNode? right;
55

6-
TreeNode([
7-
this.val = 0,
8-
this.left,
9-
this.right,
10-
]);
6+
TreeNode([this.val = 0, this.left, this.right]);
117
}
File renamed without changes.
File renamed without changes.

lib/easy/balanced_binary_tree.dart renamed to lib/easy/110_balanced_binary_tree.dart

+2-8
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ class Solution {
88
if (root != null) {
99
var l = _maxHeight(root.left);
1010
var r = _maxHeight(root.right);
11-
return (l - r).abs() < 2 &&
12-
isBalanced(root.left) &&
13-
isBalanced(root.right);
11+
return (l - r).abs() < 2 && isBalanced(root.left) && isBalanced(root.right);
1412
}
1513
return true;
1614
}
1715

1816
int _maxHeight(TreeNode? node) {
1917
if (node != null) {
20-
return 1 +
21-
max(
22-
_maxHeight(node.left),
23-
_maxHeight(node.right),
24-
);
18+
return 1 + max(_maxHeight(node.left), _maxHeight(node.right));
2519
}
2620
return 0;
2721
}

lib/easy/minimum_depth_of_binary_tree.dart renamed to lib/easy/111_minimum_depth_of_binary_tree.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ class Solution {
1313
} else if (root.right == null) {
1414
return minDepth(root.left) + 1;
1515
}
16-
return min(
17-
minDepth(root.left) + 1,
18-
minDepth(root.right) + 1,
19-
);
16+
return min(minDepth(root.left) + 1, minDepth(root.right) + 1);
2017
}
2118
return 0;
2219
}

lib/easy/path_sum.dart renamed to lib/easy/112_path_sum.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class Solution {
1111
if (node.left == null && node.right == null) {
1212
return node.val + count == targetSum;
1313
}
14-
return _sum(node.left, targetSum, node.val + count) ||
15-
_sum(node.right, targetSum, node.val + count);
14+
return _sum(node.left, targetSum, node.val + count) || _sum(node.right, targetSum, node.val + count);
1615
}
1716
return false;
1817
}
File renamed without changes.

lib/easy/roman_to_integer.dart renamed to lib/easy/13_roman_to_integer.dart

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// https://leetcode.com/problems/roman-to-integer/
22
class Solution {
33
int romanToInt(String s) {
4-
final values = <String, int>{
5-
'I': 1,
6-
'V': 5,
7-
'X': 10,
8-
'L': 50,
9-
'C': 100,
10-
'D': 500,
11-
'M': 1000,
12-
};
4+
final values = <String, int>{'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000};
135
int result = 0;
146
for (int i = s.length - 1; i >= 0; i--) {
157
int curr = values[s[i]]!;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/easy/merge_sorted_array.dart renamed to lib/easy/88_merge_sorted_array.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ class Solution {
44
var j = n - 1;
55
var l = m + n - 1;
66
while (l >= 0) {
7-
var num =
8-
j < 0 || (i >= 0 && nums1[i] > nums2[j]) ? nums1[i--] : nums2[j--];
7+
var num = j < 0 || (i >= 0 && nums1[i] > nums2[j]) ? nums1[i--] : nums2[j--];
98
nums1[l--] = num;
109
}
1110
}

lib/easy/palindrome_number.dart renamed to lib/easy/9_palindrome_number.dart

-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ class Solution {
1414
return rev == x;
1515
}
1616
}
17-

pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,4 @@ packages:
370370
source: hosted
371371
version: "3.1.1"
372372
sdks:
373-
dart: ">=3.7.2 <4.0.0"
373+
dart: ">=3.6.9 <4.0.0"

pubspec.yaml

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

66
environment:
7-
sdk: '>=3.7.2 <4.0.0'
7+
sdk: '>=3.6.9 <4.0.0'
88

99
dev_dependencies:
1010
lints: ^5.1.1

test/easy/same_tree_test.dart renamed to test/easy/100_same_tree_test.dart

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import 'package:leetcode_dart/common/tree_node.dart';
2-
import 'package:leetcode_dart/easy/same_tree.dart';
2+
import 'package:leetcode_dart/easy/100_same_tree.dart';
33
import 'package:test/test.dart';
44

55
void main() {
66
group(
77
'Example tests',
88
() {
9-
final st = Solution();
9+
final solution = Solution();
10+
1011
test(
1112
'true',
1213
() => expect(
1314
true,
14-
st.isSameTree(
15+
solution.isSameTree(
1516
TreeNode(
1617
1,
1718
TreeNode(2),
@@ -29,23 +30,24 @@ void main() {
2930
'false',
3031
() => expect(
3132
false,
32-
st.isSameTree(
33-
TreeNode(
34-
1,
35-
TreeNode(2),
36-
),
37-
TreeNode(
38-
1,
39-
null,
40-
TreeNode(2),
41-
)),
33+
solution.isSameTree(
34+
TreeNode(
35+
1,
36+
TreeNode(2),
37+
),
38+
TreeNode(
39+
1,
40+
null,
41+
TreeNode(2),
42+
),
43+
),
4244
),
4345
);
4446
test(
4547
'false',
4648
() => expect(
4749
false,
48-
st.isSameTree(
50+
solution.isSameTree(
4951
TreeNode(
5052
1,
5153
TreeNode(2),

test/easy/symmetric_tree_test.dart renamed to test/easy/101_symmetric_tree_test.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import 'package:leetcode_dart/common/tree_node.dart';
2-
import 'package:leetcode_dart/easy/symmetric_tree.dart';
2+
import 'package:leetcode_dart/easy/101_symmetric_tree.dart';
33
import 'package:test/test.dart';
44

55
void main() {
66
group(
77
'Example tests',
88
() {
9-
final st = Solution();
9+
final solution = Solution();
10+
1011
test(
1112
'true',
1213
() => expect(
1314
true,
14-
st.isSymmetric(
15+
solution.isSymmetric(
1516
TreeNode(
1617
1,
1718
TreeNode(
@@ -32,7 +33,7 @@ void main() {
3233
'false',
3334
() => expect(
3435
false,
35-
st.isSymmetric(
36+
solution.isSymmetric(
3637
TreeNode(
3738
1,
3839
TreeNode(

test/easy/maximum_depth_of_binary_tree_test.dart renamed to test/easy/104_maximum_depth_of_binary_tree_test.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import 'package:leetcode_dart/common/tree_node.dart';
2-
import 'package:leetcode_dart/easy/maximum_depth_of_binary_tree.dart';
2+
import 'package:leetcode_dart/easy/104_maximum_depth_of_binary_tree.dart';
33
import 'package:test/test.dart';
44

55
void main() {
66
group(
77
'Example tests',
88
() {
9-
final mdoft = Solution();
9+
final solution = Solution();
10+
1011
test(
1112
'3',
1213
() => expect(
1314
3,
14-
mdoft.maxDepth(
15+
solution.maxDepth(
1516
TreeNode(
1617
3,
1718
TreeNode(9),
@@ -28,7 +29,7 @@ void main() {
2829
'2',
2930
() => expect(
3031
2,
31-
mdoft.maxDepth(
32+
solution.maxDepth(
3233
TreeNode(
3334
1,
3435
null,

test/easy/convert_sorted_array_to_binary_search_tree_test.dart renamed to test/easy/108_convert_sorted_array_to_binary_search_tree_test.dart

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:leetcode_dart/common/tree_node.dart';
2-
import 'package:leetcode_dart/easy/convert_sorted_array_to_binary_search_tree.dart';
2+
import 'package:leetcode_dart/easy/108_convert_sorted_array_to_binary_search_tree.dart';
33
import 'package:test/test.dart';
44

55
import '../common/binary_tree_helper.dart';
@@ -8,7 +8,8 @@ void main() {
88
group(
99
'Example tests',
1010
() {
11-
final csatbst = Solution();
11+
final solution = Solution();
12+
1213
test(
1314
'[0, -10, 5, null, -3, null, 9]',
1415
() => expect(
@@ -27,7 +28,7 @@ void main() {
2728
TreeNode(9),
2829
),
2930
),
30-
csatbst.sortedArrayToBST(
31+
solution.sortedArrayToBST(
3132
[-10, -3, 0, 5, 9],
3233
),
3334
),
@@ -43,7 +44,9 @@ void main() {
4344
null,
4445
TreeNode(1),
4546
),
46-
csatbst.sortedArrayToBST([3, 1]),
47+
solution.sortedArrayToBST(
48+
[3, 1],
49+
),
4750
),
4851
),
4952
);

0 commit comments

Comments
 (0)