LeetCode 1998. GCD Sort of an Array

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Prehaps we can do without 'pre'?
for num in range(2, max(nums)):
if primes[num]:
for m in range(num*(num-1), max(nums)+1, num):
if m in numSet:
union(num, m)

rachitsingh
Автор

Thanks for the video man, Whats your codeforces handle?

mrdude
Автор

I m confused and tried to implement
lets say 2, 3 and 6 are in nums
prev = 3 and its parent is 3
and now when 6 comes, 6 parent is 2

cant union 2 and 3 right
please explain

girirajsaigal
Автор

if initializing the pre with p, there maybe no need to add a judegement that if pre > 0.
Hope I'm right.

boyu
Автор

Eg:
7 21 3
from seive first round
3 parent is 3
21 parent is 3

when 7 comes
21 parent is 3
7 parent is 7
we end up with union of 3 and 7
please explain

girirajsaigal