0291-0300

291. Word Pattern II $\star\star\star$

292. Nim Game $\star$

293. Flip Game $\star$

294. Flip Game II $\star\star$

295. Find Median from Data Stream $\star\star\star$

296. Best Meeting Point $\star\star\star$

297. Serialize and Deserialize Binary Tree $\star\star\star$

298. Binary Tree Longest Consecutive Sequence $\star\star$

299. Bulls and Cows $\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
 public:
  string getHint(string secans, string guess) {
    int A = 0;
    int B = 0;
    map<char, int> map1;
    map<char, int> map2;

    for (int i = 0; i < secans.length(); ++i) {
      if (secans[i] == guess[i])
        ++A;
      else {
        ++map1[secans[i]];
        ++map2[guess[i]];
      }
    }

    for (int i = 0; i <= 9; ++i) B += min(map1['0' + i], map2['0' + i]);

    return to_string(A) + "A" + to_string(B) + "B";
  }
};

300. Longest Increasing Subsequence $\star\star$