首页 > 其他 > 详细

leetcode 923. 3Sum With Multiplicity

时间:2019-04-04 23:36:15      阅读:145      评论:0      收藏:0      [点我收藏+]

When dealing with combination number problems, I think easy-to-write code is better than fast code.....

class Solution {
    public int threeSumMulti(int[] A, int target) {
        Map<Integer, Integer> m = new HashMap<Integer, Integer>();
        int P = 1000000007;
        int ret = 0;
        for (int i = 0; i < A.length; ++i) {
            int v1 = A[i];
            for (int j = i + 1; j < A.length; ++j) {
                int v2 = A[j];
                int c = m.getOrDefault(target - v1 - v2, 0);
                if (c == 0) continue;
                ret = (ret + c) % P;
            }
            m.put(v1, m.getOrDefault(v1, 0) + 1);
        }
        return ret;
    }
}

leetcode 923. 3Sum With Multiplicity

原文:https://www.cnblogs.com/exhausttolive/p/10657395.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!