C# Simple Solution


  • 0
    E

    ''''
    public class Solution {
    public bool JudgeCircle(string moves) {

        int x = 0, y = 0;
        
        foreach(char chr in moves){
            
            if(chr == 'U'){
                
                y++;
            }
            else if(chr == 'D'){
                
               y--;
            }
            else if(chr == 'L'){
                
               x--;
            }
            else{
                
               x++;
            }
        }
        
        if(x == 0 && y == 0){
            
            return true;
        }
        else{
            
            return false;
        }
        
    }
    

    }
    ''''


Log in to reply
 

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