Java easy to understand solution


  • 0
    A
    public class Solution {
        public boolean circularArrayLoop(int[] nums) {
            int n=nums.length;
            
            for(int i=0;i<n;){
                if(nums[i]+i>=0){
                    i=nums[i]+i;
                    if(i>n)
                        i=i-n;
                    if(i==0)
                        return false;
                    if(i==n)
                        return true;
                    
                }else
                return false;
            }
        return false;
        }
    }
    

  • 0
    A

    @apoo123 can you please explain logic behind it


Log in to reply
 

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