0591-0600

591. Tag Validator $\star\star\star$

592. Fraction Addition and Subtraction $\star\star$

593. Valid Square $\star\star$

594. Longest Harmonious Subsequence $\star$

595. Big Countries $\star$

596. Classes More Than 5 Students $\star$

597. Friend Requests I: Overall Acceptance Rate $\star$

598. Range Addition II $\star$

599. Minimum Index Sum of Two Lists $\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
 public:
  vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {
    vector<string> ans;

    unordered_map<string, int> map;
    for (int i = 0; i < list1.size(); ++i) map[list1[i]] = i;

    int min = INT_MAX;

    for (int i = 0; i < list2.size(); ++i) {
      if (!map.count(list2[i])) continue;
      int sum = map[list2[i]] + i;
      if (sum < min) ans.clear();
      if (sum <= min) {
        min = sum;
        ans.push_back(list2[i]);
      }
    }

    return ans;
  }
};

600. Non-negative Integers without Consecutive Ones $\star\star\star$