HXXXXJ

find celebrity

Mar 23rd, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.33 KB | None | 0 0
  1. ```swift
  2. knows(i, j)
  3. i 知道 j
  4.         for i in 1..< n {
  5.             if knows(celeb, i) {
  6.                 celeb = i
  7.             }
  8.         }
  9.         for j in 0..< n where celeb != j {
  10.             if (knows(celeb, j)) || !knows(j, celeb) {// there is no celeb
  11.                 return -1
  12.             }
  13.         }
  14.         return celeb
Advertisement
Add Comment
Please, Sign In to add comment