Clean JAVA Code


  • 0
    A
    public boolean isStrobogrammatic(String num) {
    	Map<Character, Character> map = new HashMap<Character, Character>();
    	map.put('6', '9');
    	map.put('9', '6');
    	map.put('1', '1');
    	map.put('8', '8');
    	map.put('0', '0');
    
    	int i = 0;
    	int j = num.length() - 1;
    	while (i <= j) {
    		if (map.get(num.charAt(i)) != null && map.get(num.charAt(i)) == num.charAt(j)) {
    			i++;
    			j--;
    		} else
    			return false;
    	}
    	return true;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.