246 Strobogrammatic Number
1. Question
2. Implementation
class Solution {
public boolean isStrobogrammatic(String num) {
Map<Character, Character> map = new HashMap<>();
map.put('0', '0');
map.put('1', '1');
map.put('6', '9');
map.put('8', '8');
map.put('9', '6');
int start = 0, end = num.length() - 1;
while (start <= end) {
if (!map.containsKey(num.charAt(start)) || map.get(num.charAt(start)) != num.charAt(end)) {
return false;
}
++start;
--end;
}
return true;
}
}3. Time & Space Complexity
Last updated