Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int numTeams(int[] rating) {
- final int n = rating.length;
- int[][] asc = new int[4][n];
- int[][] desc = new int[4][n];
- for (int i = 0; i < n; i++) {
- asc[1][i] = 1;
- desc[1][i] = 1;
- }
- int ret = 0;
- for (int i = 2; i <= 3; i++) {
- for (int r = 1; r < n; r++) {
- for (int l = 0; l < r; l++) {
- if (rating[l] < rating[r])
- asc[i][r] += asc[i-1][l];
- if (rating[l] > rating[r])
- desc[i][r] += desc[i-1][l];
- }
- if (i == 3)
- ret += asc[i][r] + desc[i][r];
- }
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement