java solution


  • 0
    1
    class Solution {
        public boolean judgeCircle(String moves) {
    		int rc=findCharCount(moves, 'R');
    		int lc=findCharCount(moves, 'L');
    		int uc=findCharCount(moves, 'U');
    		int dc=findCharCount(moves, 'D');
    		if(rc==lc&&uc==dc){
    			return true;
    		}
            return false;
        }
    	
    	public int findCharCount(String str,char c){
    		int count=0;
    		for(int i=0;i<str.length();i++){
    			if(str.charAt(i)==c){
    				count++;
    			}
    		}
    		return count;
    	}
    }
    

Log in to reply
 

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