From 9d484457c6fa861da8126ff3fd9a00cdbb0993b6 Mon Sep 17 00:00:00 2001 From: cdbluejr Date: Wed, 23 Oct 2024 16:10:54 +0000 Subject: [PATCH 1/2] feat: Lesson 12 Game Result / Stack by Dwight Blue --- .../codedifferently/lesson12/Lesson12.java | 29 +++++++++++++++++-- .../com/codedifferently/lesson12/Stack.java | 16 ++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index af7663e90..9aa60aaed 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -2,11 +2,34 @@ public class Lesson12 { + public Lesson12() { + + } + /** * Provide the solution to LeetCode 3062 here: * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game */ public String gameResult(ListNode head) { - return null; - } -} + var o = 0; + var e = 0; + while (head != null){ + if (head.val > head.next.val){ + e++; + } + else{ + o++; + } + head = head.next.next; + } + if ( e > o) { + return "Even"; + } else if ( e Date: Wed, 23 Oct 2024 16:17:17 +0000 Subject: [PATCH 2/2] fix: Formatting issue by Dwight Blue --- .../codedifferently/lesson12/Lesson12.java | 41 ++++++++----------- .../com/codedifferently/lesson12/Stack.java | 5 +-- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java index 9aa60aaed..99065939b 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java @@ -2,34 +2,27 @@ public class Lesson12 { - public Lesson12() { - - } + public Lesson12() {} /** * Provide the solution to LeetCode 3062 here: * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game */ public String gameResult(ListNode head) { - var o = 0; - var e = 0; - while (head != null){ - if (head.val > head.next.val){ - e++; - } - else{ - o++; - } - head = head.next.next; - } - if ( e > o) { - return "Even"; - } else if ( e head.next.val) { + e++; + } else { + o++; } - else - return "Tie"; - -} - - } \ No newline at end of file + head = head.next.next; + } + if (e > o) { + return "Even"; + } else if (e < o) { + return "Odd"; + } else return "Tie"; + } +} diff --git a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java index 953a00cee..3fa413c10 100644 --- a/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java +++ b/lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java @@ -1,6 +1,5 @@ package com.codedifferently.lesson12; - /** Implement the below Stack by providing code for the class methods. */ public class Stack { private ListNode top; @@ -8,8 +7,9 @@ public class Stack { public Stack() { this.top = null; } + public void push(int value) { - ListNode newTop = new ListNode (value); + ListNode newTop = new ListNode(value); newTop.next = top; top = newTop; } @@ -29,4 +29,3 @@ public boolean isEmpty() { return top == null; } } -