如何摆脱内部循环而不会破裂
因此,我正在研究这个程序,并且正在尝试从数组中删除重复项,并且我想离开内部循环,在每次迭代之后回到外循环,但我不希望内部循环重新开始,因为现在每次我都会开始突破内部循环的下一个迭代,内部循环再次开始,所以num始终是1
def removeDuplicates(self, nums: List[int]) -> int:
for i in range(len(nums)-1):
curr = nums[i+1]
for num in nums:
if num == curr:
print('removed ' , num)
break
so I am working on this program and I am trying to remove duplicates from an array and I wanna leave the inner loop and go back to the outer loop after every iteration but I don't want the inner loop to start over because now everytime I break out of the inner loop the next iteration the inner loop starts all over again so num is always 1
def removeDuplicates(self, nums: List[int]) -> int:
for i in range(len(nums)-1):
curr = nums[i+1]
for num in nums:
if num == curr:
print('removed ' , num)
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然后只使用一组
Simply use a set then