0521-0530

521. Longest Uncommon Subsequence I \star

522. Longest Uncommon Subsequence II \star\star

523. Continuous Subarray Sum \star\star

524. Longest Word in Dictionary through Deleting \star\star

525. Contiguous Array \star\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:
  int findMaxLength(vector<int>& nums) {
    if (nums.empty()) return 0;

    int ans = 0;
    int sum = 0;
    unordered_map<int, int> map;

    for (int i = 0; i < nums.size(); ++i) {
      sum += nums[i] ? 1 : -1;
      if (sum == 0) {
        ans = i + 1;
      } else if (map.count(sum)) {
        ans = max(ans, i - map[sum]);
      } else {
        map[sum] = i;
      }
    }

    return ans;
  }
};

526. Beautiful Arrangement \star\star

527. Word Abbreviation \star\star\star

528. Random Pick with Weight \star\star

529. Minesweeper \star\star

530. Minimum Absolute Difference in BST \star