package leetcode;

/**
 * https://leetcode.com/problems/longest-harmonious-subsequence/
 */
public class Problem597 {
    public int findLHS(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem597 prob = new Problem597();
        System.out.println(prob.findLHS(new int[]{1, 3, 2, 2, 5, 2, 3, 7})); // 5
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -209,211 +209,693 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem597 prob = new Problem597();%0A        System.out.println(prob.findLHS(new int%5B%5D%7B1, 3, 2, 2, 5, 2, 3, 7%7D)); // 5
+Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (!map.containsKey(nums%5Bi%5D)) %7B%0A                map.put(nums%5Bi%5D, 1);%0A            %7D else %7B%0A                map.put(nums%5Bi%5D, map.get(nums%5Bi%5D) + 1);%0A            %7D%0A        %7D%0A        int max = 0;%0A        for (Integer i : map.keySet()) %7B%0A            int count = map.get(i);%0A            int c1 = map.getOrDefault(i + 1, 0);%0A            int c2 = map.getOrDefault(i - 1, 0);%0A            if (c1 == 0 && c2 == 0) %7B%0A                max = Math.max(max, 0);%0A            %7D else %7B%0A                max = Math.max(max, Math.max(count + c1, count + c2));%0A            %7D%0A        %7D%0A        return max;
 %0A   

Solve problem 597