diff --git a/README.md b/README.md index 35a49c7..596bf2f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ 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) | +| 263. Ugly Number | [Link](https://lettcode.com/problems/ugly-number/) | [Link](./lib/easy/263_ugly_number.dart) | | 500. Keyboard Row | [Link](https://leetcode.com/problems/keyboard-row/) | [Link](./lib/easy/500_keyboard_row.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/263_ugly_number.dart b/lib/easy/263_ugly_number.dart new file mode 100644 index 0000000..16012ca --- /dev/null +++ b/lib/easy/263_ugly_number.dart @@ -0,0 +1,15 @@ +class Solution { + bool isUgly(int n) { + if (n <= 0) { + return false; + } + + for (final p in [2, 3, 5]) { + while (n % p == 0) { + n ~/= p; + } + } + + return n == 1; + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 250ce18..2d391ad 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.4 +version: 1.0.5 homepage: https://github.com/fartem/leetcode-dart environment: diff --git a/test/easy/263_ugly_number_test.dart b/test/easy/263_ugly_number_test.dart new file mode 100644 index 0000000..59ed44c --- /dev/null +++ b/test/easy/263_ugly_number_test.dart @@ -0,0 +1,33 @@ +import 'package:leetcode_dart/easy/263_ugly_number.dart'; +import 'package:test/test.dart'; + +void main() { + group( + 'Example tests', + () { + final solution = Solution(); + + test( + '6', + () => expect( + true, + solution.isUgly(6), + ), + ); + test( + '1', + () => expect( + true, + solution.isUgly(6), + ), + ); + test( + '14', + () => expect( + true, + solution.isUgly(6), + ), + ); + }, + ); +}