Algs4-1.4TwoSum

public class TwoSum
{
    public static int count(int[] a)
    {
        int N=a.length;
        int cnt=0;
        for (int i=0;i<N;i++)
            for (int j=i+1;j<N;j++)
                  if(a[i]+a[j]==0)
                       cnt++;
        return cnt;
    }
   
    public static void main(String[] args)
    {
        int[] a=In.readInts(args[0]);
        StdOut.println(count(a));
    }
}

posted @ 2018-10-26 08:52  修电脑的龙生  阅读(91)  评论(0编辑  收藏  举报