diff --git a/README.md b/README.md index db871e1..48ecbca 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,5 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 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) | | 112. Path Sum | [Link](https://leetcode.com/problems/path-sum/) | [Link](./lib/easy/112_path_sum.dart) | | 118. Pascal's Triangle | [Link](https://leetcode.com/problems/pascals-triangle/) | [Link](./lib/easy/118_pascals_triangle.dart) | +| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.dart) | | 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.dart) | diff --git a/lib/easy/3280_convert_date_to_binary.dart b/lib/easy/3280_convert_date_to_binary.dart new file mode 100644 index 0000000..0e3d804 --- /dev/null +++ b/lib/easy/3280_convert_date_to_binary.dart @@ -0,0 +1,10 @@ +class Solution { + String convertDateToBinary(String date) { + return date + .split('-') + .map( + (part) => int.parse(part).toRadixString(2), + ) + .join('-'); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 06838ea..aff6720 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: leetcode_dart description: Some solved problems from https://leetcode.com on Dart -version: 1.0.2 +version: 1.0.3 homepage: https://github.com/fartem/leetcode-dart environment: diff --git a/test/easy/3280_convert_date_to_binary_test.dart b/test/easy/3280_convert_date_to_binary_test.dart new file mode 100644 index 0000000..e309b9b --- /dev/null +++ b/test/easy/3280_convert_date_to_binary_test.dart @@ -0,0 +1,30 @@ +import 'package:leetcode_dart/easy/3280_convert_date_to_binary.dart'; +import 'package:test/test.dart'; + +void main() { + group( + 'Example tests', + () { + final solution = Solution(); + + test( + '100000100000-10-11101', + () => expect( + '100000100000-10-11101', + solution.convertDateToBinary( + '2080-02-29', + ), + ), + ); + test( + '11101101100-1-1', + () => expect( + '11101101100-1-1', + solution.convertDateToBinary( + '1900-01-01', + ), + ), + ); + }, + ); +}