-
Notifications
You must be signed in to change notification settings - Fork 25
feat: adds Kimberlee's Lesson 12: Data Structures: Stacks, Queue, Linked Lists #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dfd7afe
feats: adds Kimberlee's Lesson-12: Data Structures:
haldanek 811220e
Merge remote-tracking branch 'refs/remotes/origin/Lesson_12' into Les…
haldanek 73fe7c3
Merge branch 'code-differently:main' into Lesson_12
haldanek a50a4ee
Merge branch 'code-differently:main' into Lesson_12
haldanek 6b1b0f6
chore: added a missing semicolon
haldanek 14e7a2b
feat: adding lesson 12 Linked List Games again
haldanek ad543f8
Merge remote-tracking branch 'refs/remotes/origin/Lesson_12' into Les…
haldanek 9c96edc
feat: adds Kimberlee's ListNode.java file
haldanek ed5ac51
chore: deleted unnecessary file
haldanek 48f21eb
feat: adds Kimberlee's lesson 12 Stack.java file
haldanek 612a189
fix: edited lesson12.java and ListNode.java files
haldanek 1a6ff0d
fix: removed all unused code
haldanek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 84 additions & 2 deletions
86
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,94 @@ | ||
package com.codedifferently.lesson12; | ||
|
||
/* import java.util.LinkedList; */ | ||
import java.util.ArrayList; | ||
/* import java.util.List; */ | ||
import java.util.List; | ||
|
||
public class 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; | ||
/* class TeamNode { | ||
haldanek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int data; | ||
TeamNode next; | ||
|
||
public TeamNode(int data) { | ||
this.data = data; | ||
this.next = null; | ||
} | ||
} | ||
|
||
class LinkedList { | ||
TeamNode head; | ||
|
||
public void add(int data) { | ||
TeamNode newTeamNode = new TeamNode(data); | ||
if (head == null) { | ||
head = newTeamNode; | ||
} else { | ||
TeamNode temp = head; | ||
while (temp.next != null) { | ||
temp = temp.next; | ||
} | ||
temp.next = newTeamNode; | ||
} | ||
} */ | ||
|
||
public String gameResult(/* Team */ListNode head) { | ||
List<String> result = new ArrayList<>(); | ||
int evenCounter = 0; | ||
int oddCounter = 0; | ||
/* Team */ListNode current = head; | ||
|
||
while (current != null && current.next != null) { | ||
int evenValue = current.data; | ||
int oddValue = current.next.data; | ||
|
||
if (evenValue > oddValue) { | ||
result.add("even"); | ||
evenCounter++; | ||
} else { | ||
result.add("odd"); | ||
oddCounter++; | ||
} | ||
|
||
current = current.next.next; | ||
} | ||
|
||
String winningTeam; | ||
if (evenCounter > oddCounter) { | ||
winningTeam = "even"; | ||
} else if (oddCounter > evenCounter) { | ||
winningTeam = "odd"; | ||
} else { | ||
winningTeam = "tie"; | ||
} | ||
|
||
System.out.println("Node team with higher value in each pair: " + result); | ||
System.out.println("The team with the most high-values is: " + winningTeam); | ||
|
||
return winningTeam; | ||
} | ||
} | ||
|
||
|
||
/* public class Main { | ||
public static void main(String[] args) { | ||
LinkedList list = new LinkedList(); | ||
|
||
list.add(2); | ||
list.add(5); | ||
list.add(4); | ||
list.add(7); | ||
list.add(20); | ||
list.add(5); | ||
|
||
String winningTeam = list.gameResult(list.head); | ||
|
||
System.out.println("Team with most high-value pairs: " + winningTeam); | ||
} | ||
} | ||
} */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.