Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 564 Bytes

1583.-count-unhappy-friends.md

File metadata and controls

23 lines (17 loc) · 564 Bytes

1583. Count Unhappy Friends

class Solution:
    def unhappyFriends(self, n: int, preferences: List[List[int]], pairs: List[List[int]]) -> int:

        res = set()
        pair_dit = {}
        for x,y in pairs:
            pair_dit[x] = y
            pair_dit[y] = x


        for x in range(n):
            y = pair_dit[x]

            for u in preferences[x][:preferences[x].index(y)]:
                v = pair_dit[u]
                if preferences[u].index(x) < preferences[u].index(v):
                    res.add(x)
        return len(res)