File tree Expand file tree Collapse file tree 1 file changed +18
-24
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 1 file changed +18
-24
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class Lesson12 {
4
4
5
- public Lesson12 () {
6
-
7
- }
5
+ public Lesson12 () {}
8
6
9
7
/**
10
8
* Provide the solution to LeetCode 3062 here:
11
9
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
12
10
*/
13
11
public String gameResult (ListNode head ) {
14
- ListNode current = head ;
15
- int oddPoints = 0 ;
16
- int evenPoints = 0 ;
17
- while (current != null ){
18
- if (current .val > current .next .val ){
19
- evenPoints ++;
20
- }
21
- else {
22
- oddPoints ++;
23
- }
24
- current = current .next .next ;
25
- }
26
- if ( evenPoints > oddPoints ) {
27
- return "Even" ;
28
- } else if ( evenPoints <oddPoints ) {
29
- return "Odd" ;
12
+ ListNode current = head ;
13
+ int oddPoints = 0 ;
14
+ int evenPoints = 0 ;
15
+ while (current != null ) {
16
+ if (current .val > current .next .val ) {
17
+ evenPoints ++;
18
+ } else {
19
+ oddPoints ++;
30
20
}
31
- else return "Tie" ;
32
-
33
- }
34
-
35
- }
21
+ current = current .next .next ;
22
+ }
23
+ if (evenPoints > oddPoints ) {
24
+ return "Even" ;
25
+ } else if (evenPoints < oddPoints ) {
26
+ return "Odd" ;
27
+ } else return "Tie" ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments