Leetcode 練習:2022-01-03

January 03, 2022

Find the Town Judge

題號:997

def find_judge(n, trust)
  return 1 if n == 1
  people = Array.new(n, 0)
  trust.each do |truster, trustee|
    people[trustee - 1] += 1
    people[truster - 1] = -1.0/0.0 # -Infinity
  end
  people.index(n-1) ? people.index(n-1) + 1 : -1
end

Profile picture

Wei Hung 的筆記 / 部落格。