File tree Expand file tree Collapse file tree 4 files changed +49
-47
lines changed
lesson_12/structs_java/structs_app/src
main/java/com/codedifferently/lesson12
test/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 4 files changed +49
-47
lines changed Original file line number Diff line number Diff line change @@ -6,30 +6,30 @@ public class Lesson12 {
6
6
* Provide the solution to LeetCode 3062 here:
7
7
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8
8
*/
9
- public String gameResult (ListNode head ) {
10
- int oddPoints = 0 ;
11
- int evenPoints = 0 ;
12
- ListNode current = head ;
13
-
14
- while (current != null && current .next != null ) {
15
- int evenValue = current .val ;
16
- int oddValue = current .next .val ;
17
-
18
- if (evenValue > oddValue ) {
19
- evenPoints ++;
20
- } else if (oddValue > evenValue ) {
21
- oddPoints ++;
22
- }
9
+ public String gameResult (ListNode head ) {
10
+ int oddPoints = 0 ;
11
+ int evenPoints = 0 ;
12
+ ListNode current = head ;
23
13
24
- current = current .next .next ;
25
- }
26
-
27
- if (evenPoints > oddPoints ) {
28
- return "Even" ;
29
- } else if (oddPoints > evenPoints ) {
30
- return "Odd" ;
31
- } else {
32
- return "Tie" ;
33
- }
14
+ while (current != null && current .next != null ) {
15
+ int evenValue = current .val ;
16
+ int oddValue = current .next .val ;
17
+
18
+ if (evenValue > oddValue ) {
19
+ evenPoints ++;
20
+ } else if (oddValue > evenValue ) {
21
+ oddPoints ++;
22
+ }
23
+
24
+ current = current .next .next ;
25
+ }
26
+
27
+ if (evenPoints > oddPoints ) {
28
+ return "Even" ;
29
+ } else if (oddPoints > evenPoints ) {
30
+ return "Odd" ;
31
+ } else {
32
+ return "Tie" ;
34
33
}
35
- }
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -9,29 +9,29 @@ public Stack() {
9
9
}
10
10
11
11
public void push (int value ) {
12
- ListNode node = new ListNode (value );
13
- node .next = top ;
14
- top = node ;
15
- }
12
+ ListNode node = new ListNode (value );
13
+ node .next = top ;
14
+ top = node ;
15
+ }
16
16
17
- public int pop () {
18
- if (isEmpty ()){
19
- throw new IllegalStateException ("Stack has no values" );
20
- }
21
- int valToPop = top .val ;
22
- top = top .next ;
23
- return valToPop ;
24
- }
17
+ public int pop () {
18
+ if (isEmpty ()) {
19
+ throw new IllegalStateException ("Stack has no values" );
20
+ }
21
+ int valToPop = top .val ;
22
+ top = top .next ;
23
+ return valToPop ;
24
+ }
25
25
26
- public int peek () {
27
- if (isEmpty ()){
28
- throw new IllegalStateException ("Stack has no values" );
29
- }
26
+ public int peek () {
27
+ if (isEmpty ()) {
28
+ throw new IllegalStateException ("Stack has no values" );
29
+ }
30
30
31
- return top .val ;
32
- }
31
+ return top .val ;
32
+ }
33
33
34
- public boolean isEmpty () {
35
- return top == null ;
36
- }
37
- }
34
+ public boolean isEmpty () {
35
+ return top == null ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson12 ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+
4
5
import org .junit .jupiter .api .Test ;
5
6
6
7
class Lesson12Test {
Original file line number Diff line number Diff line change 4
4
import static org .junit .jupiter .api .Assertions .assertFalse ;
5
5
import static org .junit .jupiter .api .Assertions .assertThrows ;
6
6
import static org .junit .jupiter .api .Assertions .assertTrue ;
7
+
7
8
import org .junit .jupiter .api .Test ;
8
9
9
10
class StackTest {
You can’t perform that action at this time.
0 commit comments