Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. class Solution {
  2.     public int numTeams(int[] rating) {
  3.         final int n  = rating.length;
  4.         int[][] asc = new int[4][n];
  5.         int[][] desc = new int[4][n];
  6.         for (int i = 0; i < n; i++) {
  7.             asc[1][i] = 1;
  8.             desc[1][i] = 1;
  9.         }
  10.         int ret = 0;
  11.         for (int i = 2; i <= 3; i++) {
  12.             for (int r = 1; r < n; r++) {
  13.                 for (int l = 0; l < r; l++) {
  14.                     if (rating[l] < rating[r])
  15.                         asc[i][r] += asc[i-1][l];
  16.                     if (rating[l] > rating[r])
  17.                         desc[i][r] += desc[i-1][l];
  18.                 }
  19.                 if (i == 3)
  20.                     ret += asc[i][r] + desc[i][r];
  21.             }
  22.            
  23.         }
  24.         return ret;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement