File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 215
215
| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | [](src/ShortestWordDistance.java) | |
216
216
| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | |
217
217
| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | |
218
- | 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | |
219
- | 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | |
218
+ | 246 | 🔒 [Strobogrammatic Number](https://leetcode.com/problems/strobogrammatic-number) | [](src/StrobogrammaticNumber.java) | |
219
+ | 247 | 🔒 [Strobogrammatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | |
220
220
| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | |
221
221
| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | |
222
222
| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/strobogrammatic-number
2
+ // T: O(N)
3
+ // S: O(1)
4
+
5
+ import java .util .HashMap ;
6
+ import java .util .Map ;
7
+
8
+ // Strobogrammatic digits: 0, 1, 8
9
+ // Strobogrammatic interchangeable digits: 6 --> 9, 9 --> 6
10
+ public class StrobogrammaticNumber {
11
+ private static final Map <Character , Character > STROBOGRAMMATIC_MIRROR = new HashMap <>() {{
12
+ put ('0' , '0' );
13
+ put ('1' , '1' );
14
+ put ('6' , '9' );
15
+ put ('8' , '8' );
16
+ put ('9' , '6' );
17
+ }};
18
+
19
+ public boolean isStrobogrammatic (String number ) {
20
+ for (int i = 0 ; i < number .length () ; i ++) {
21
+ final char digit = number .charAt (i );
22
+ if (!STROBOGRAMMATIC_MIRROR .containsKey (digit )
23
+ || STROBOGRAMMATIC_MIRROR .get (digit ) != number .charAt (number .length () - 1 - i )
24
+ ) {
25
+ return false ;
26
+ }
27
+ }
28
+ return true ;
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments