Strobogrammatic Number (Mirror Number)

LintCode Q 644 - Strobogrammatic Number (Mirror Number)

GA mirror number is a number that looks the same when rotated 180 degrees (looked at upside down).For example, the numbers “69”, “88”, and “818” are all mirror numbers.

Write a function to determine if a number is mirror. The number is represented as a string.

Strobogrammatic Number II

Solution

Code:

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('9', '6'); map.put('8', '8');
	int i = 0, j = nums.length() - 1;
	while (i <= j) {
		if ( !map.containsKey(num.charAt(i)) || 
		      map.get(num.charAt(i)) != map.get(num.charAt(j)))
		    return false;
		i++; j--;
	}
	return true;
}

   Reprint policy


《Strobogrammatic Number (Mirror Number)》 by Tong Shi is licensed under a Creative Commons Attribution 4.0 International License
  TOC