SHARE
TWEET

Untitled

a guest Sep 16th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Alitaulukot {
  2.     long laske(int[] t) {
  3.  
  4.         int a = t[0];
  5.         int b = 0;
  6.         int c = 0;
  7.         long result = 2*t.length-1;
  8.  
  9.         for (int i = 0; i < t.length; i++) {
  10.  
  11.             if (b == 0 && t[i] != a) {
  12.                 b = t[i];
  13.             }
  14.  
  15.             if ((t[i] != a && t[i] != b) && b != 0) {
  16.                 result += sum(c);
  17.                 while(t[i-1] == b) {
  18.                     i--;
  19.                     System.out.println(t[i]);
  20.                 }
  21.                 a = t[i];
  22.                 b = 0;
  23.                 c = 0;
  24.             }
  25.  
  26.             c++;
  27.  
  28.         }
  29.         result += sum(c);
  30.         return result;
  31.  
  32.     }
  33.  
  34.     long sum(long n) {
  35.         long sum = 0;
  36.         for (int i = 0; i < n-1; i++) {
  37.             sum += i;
  38.         }
  39.         return sum;
  40.     }
  41.  
  42.  
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top