File tree 1 file changed +62
-0
lines changed
Java/src/com/longluo/contest/biweekly_contest_113
1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .longluo .contest .biweekly_contest_113 ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ /**
7
+ * https://leetcode.cn/contest/biweekly-contest-113
8
+ */
9
+ public class Problem1 {
10
+
11
+ public static int minimumRightShifts (List <Integer > nums ) {
12
+ int ans = 0 ;
13
+
14
+ int n = nums .size ();
15
+
16
+ int first = nums .get (0 );
17
+
18
+ for (int i = 1 ; i < n ; i ++) {
19
+ if (nums .get (i ) > nums .get (i - 1 )) {
20
+ continue ;
21
+ }
22
+
23
+ if (i == n - 1 && nums .get (n - 1 ) < first ) {
24
+ return 1 ;
25
+ }
26
+
27
+ for (int j = i + 1 ; j < n ; j ++) {
28
+ if (nums .get (j ) > nums .get (j - 1 )) {
29
+ if (j == n - 1 && nums .get (n - 1 ) < first ) {
30
+ return n - i ;
31
+ } else if (j == n - 1 && nums .get (n - 1 ) > first ) {
32
+ return -1 ;
33
+ }
34
+
35
+ continue ;
36
+ }
37
+
38
+ return -1 ;
39
+ }
40
+ }
41
+
42
+ return ans ;
43
+ }
44
+
45
+ public static void main (String [] args ) {
46
+ List <Integer > tst1 = new ArrayList <>();
47
+ tst1 .add (3 );
48
+ tst1 .add (4 );
49
+ tst1 .add (5 );
50
+ tst1 .add (1 );
51
+ tst1 .add (2 );
52
+
53
+ System .out .println ("2 ?= " + minimumRightShifts (tst1 ));
54
+
55
+ List <Integer > tst2 = new ArrayList <>();
56
+ tst2 .add (2 );
57
+ tst2 .add (1 );
58
+ tst2 .add (4 );
59
+
60
+ System .out .println ("-1 ?= " + minimumRightShifts (tst2 ));
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments