Detect And Remove Loop Leetcode