File tree Expand file tree Collapse file tree 2 files changed +19
-27
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +19
-27
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
- var o = 0 ;
15
- var e = 0 ;
16
- while (head != null ){
17
- if (head .val > head .next .val ){
18
- e ++;
19
- }
20
- else {
21
- o ++;
22
- }
23
- head = head .next .next ;
24
- }
25
- if ( e > o ) {
26
- return "Even" ;
27
- } else if ( e <o ) {
28
- return "Odd" ;
12
+ var o = 0 ;
13
+ var e = 0 ;
14
+ while (head != null ) {
15
+ if (head .val > head .next .val ) {
16
+ e ++;
17
+ } else {
18
+ o ++;
29
19
}
30
- else
31
- return "Tie" ;
32
-
33
- }
34
-
35
- }
20
+ head = head .next .next ;
21
+ }
22
+ if (e > o ) {
23
+ return "Even" ;
24
+ } else if (e < o ) {
25
+ return "Odd" ;
26
+ } else return "Tie" ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson12 ;
2
2
3
-
4
3
/** Implement the below Stack by providing code for the class methods. */
5
4
public class Stack {
6
5
private ListNode top ;
7
6
8
7
public Stack () {
9
8
this .top = null ;
10
9
}
10
+
11
11
public void push (int value ) {
12
- ListNode newTop = new ListNode (value );
12
+ ListNode newTop = new ListNode (value );
13
13
newTop .next = top ;
14
14
top = newTop ;
15
15
}
@@ -29,4 +29,3 @@ public boolean isEmpty() {
29
29
return top == null ;
30
30
}
31
31
}
32
-
You can’t perform that action at this time.
0 commit comments