File tree 1 file changed +23
-19
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +23
-19
lines changed Original file line number Diff line number Diff line change @@ -45,29 +45,33 @@ Return true (self crossing)
45
45
46
46
*/
47
47
public class _335 {
48
-
49
- /**reference: https://discuss.leetcode.com/topic/38014/java-oms-with-explanation/2*/
50
- public boolean isSelfCrossing (int [] x ) {
51
- int l = x .length ;
52
- if (l <= 3 ) {
53
- return false ;
54
- }
55
-
56
- for (int i = 3 ; i < l ; i ++) {
57
- if (x [i ] >= x [i - 2 ] && x [i - 1 ] <= x [i - 3 ]) {
58
- return true ; //Fourth line crosses first line and onward
48
+ public static class Solution1 {
49
+ /** reference: https://discuss.leetcode.com/topic/38014/java-oms-with-explanation/2 */
50
+ public boolean isSelfCrossing (int [] x ) {
51
+ int l = x .length ;
52
+ if (l <= 3 ) {
53
+ return false ;
59
54
}
60
- if (i >= 4 ) {
61
- if (x [i - 1 ] == x [i - 3 ] && x [i ] + x [i - 4 ] >= x [i - 2 ]) {
62
- return true ; // Fifth line meets first line and onward
55
+
56
+ for (int i = 3 ; i < l ; i ++) {
57
+ if (x [i ] >= x [i - 2 ] && x [i - 1 ] <= x [i - 3 ]) {
58
+ return true ; //Fourth line crosses first line and onward
63
59
}
64
- }
65
- if (i >= 5 ) {
66
- if (x [i - 2 ] - x [i - 4 ] >= 0 && x [i ] >= x [i - 2 ] - x [i - 4 ] && x [i - 1 ] >= x [i - 3 ] - x [i - 5 ] && x [i - 1 ] <= x [i - 3 ]) {
67
- return true ; // Sixth line crosses first line and onward
60
+ if (i >= 4 ) {
61
+ if (x [i - 1 ] == x [i - 3 ] && x [i ] + x [i - 4 ] >= x [i - 2 ]) {
62
+ return true ; // Fifth line meets first line and onward
63
+ }
64
+ }
65
+ if (i >= 5 ) {
66
+ if (x [i - 2 ] - x [i - 4 ] >= 0
67
+ && x [i ] >= x [i - 2 ] - x [i - 4 ]
68
+ && x [i - 1 ] >= x [i - 3 ] - x [i - 5 ]
69
+ && x [i - 1 ] <= x [i - 3 ]) {
70
+ return true ; // Sixth line crosses first line and onward
71
+ }
68
72
}
69
73
}
74
+ return false ;
70
75
}
71
- return false ;
72
76
}
73
77
}
You can’t perform that action at this time.
0 commit comments