Skip to content

cand [terminology]

Terminology

Usage

  • Use for a provisional candidate that may later be accepted, rejected, or verified.
  • It is conventional in voting, search, and generated-neighbor algorithms.
  • Use compound forms such as cand1 and cand2 when multiple candidates coexist.
  • Prefer a semantic name when the candidate has a stable domain role.
cand, cnt = None, 0
for x in nums:
    if x == cand:
        cnt += 1
    elif cnt == 0:
        cand, cnt = x, 1
    else:
        cnt -= 1

See 169. Majority Element.