File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 64
64
| 203 | [ Remove Linked List Elements] ( https://leetcode.com/problems/remove-linked-list-elements ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RemoveLinkedListElements.java ) |
65
65
| 204 | [ Count Primes] ( https://leetcode.com/problems/count-primes ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/CountPrimes.java ) |
66
66
| 205 | [ Isomorphic Strings] ( https://leetcode.com/problems/isomorphic-strings ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsomorphicStrings.java ) |
67
- | 206 | [ Reverse Linked Lists] ( https://leetcode.com/problems/reverse-linked-list ) | Easy |
67
+ | 206 | [ Reverse Linked Lists] ( https://leetcode.com/problems/reverse-linked-list ) | Easy | [ ![ Java ] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( ) |
68
68
| 217 | [ Contains Duplicate] ( https://leetcode.com/problems/contains-duplicate ) | Easy |
69
69
| 219 | [ Contains Duplicate II] ( https://leetcode.com/problems/contains-duplicate-ii ) | Easy |
70
70
| 225 | [ Implement Stack using Queues] ( https://leetcode.com/problems/implement-stack-using-queues ) | Easy |
Original file line number Diff line number Diff line change
1
+ public class ReverseLinkedList {
2
+ private static class ListNode {
3
+ int val ;
4
+ ListNode next ;
5
+ }
6
+
7
+ public static ListNode reverseList (ListNode head ) {
8
+ if (head == null || head .next == null ) {
9
+ return head ;
10
+ }
11
+
12
+ ListNode current = head , ahead = head .next , temp = head .next .next ;
13
+ head .next = null ;
14
+
15
+ while (temp != null ) {
16
+ ahead .next = current ;
17
+ current = ahead ;
18
+ ahead = temp ;
19
+ temp = temp .next ;
20
+ }
21
+ ahead .next = current ;
22
+ return ahead ;
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments