Skip to content

Commit 8beee47

Browse files
authored
Merge pull request #34 from fartem/263-Ugly-Number
2025-05-01 v. 1.0.5: added "263. Ugly Number"
2 parents fd92286 + 6492303 commit 8beee47

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
@@ -38,6 +38,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
3838
| 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) |
3939
| 112. Path Sum | [Link](https://leetcode.com/problems/path-sum/) | [Link](./lib/easy/112_path_sum.dart) |
4040
| 118. Pascal's Triangle | [Link](https://leetcode.com/problems/pascals-triangle/) | [Link](./lib/easy/118_pascals_triangle.dart) |
41+
| 263. Ugly Number | [Link](https://lettcode.com/problems/ugly-number/) | [Link](./lib/easy/263_ugly_number.dart) |
4142
| 500. Keyboard Row | [Link](https://leetcode.com/problems/keyboard-row/) | [Link](./lib/easy/500_keyboard_row.dart) |
4243
| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.dart) |
4344
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.dart) |

lib/easy/263_ugly_number.dart

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
bool isUgly(int n) {
3+
if (n <= 0) {
4+
return false;
5+
}
6+
7+
for (final p in [2, 3, 5]) {
8+
while (n % p == 0) {
9+
n ~/= p;
10+
}
11+
}
12+
13+
return n == 1;
14+
}
15+
}

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.4
3+
version: 1.0.5
44
homepage: https://github.com/fartem/leetcode-dart
55

66
environment:

test/easy/263_ugly_number_test.dart

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:leetcode_dart/easy/263_ugly_number.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+
'6',
12+
() => expect(
13+
true,
14+
solution.isUgly(6),
15+
),
16+
);
17+
test(
18+
'1',
19+
() => expect(
20+
true,
21+
solution.isUgly(6),
22+
),
23+
);
24+
test(
25+
'14',
26+
() => expect(
27+
true,
28+
solution.isUgly(6),
29+
),
30+
);
31+
},
32+
);
33+
}

0 commit comments

Comments
 (0)