-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 8
More file actions
43 lines (43 loc) · 1.2 KB
/
Day 8
File metadata and controls
43 lines (43 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Mothers and Father's day Challenges day
Day 8 :
Topic: Linked List - Odd Even Linked List - https://lnkd.in/gpMgj7eU
Code -
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode oddEvenList(ListNode head) {
if (head == null) {
return null;
}
ListNode a = head;
ListNode b = head.next, c = b;
while (b != null && b.next != null) {
a.next = b.next;
a = a.next;
b.next = a.next;
b = b.next;
}
a.next = c;
return head;
}
}
----------------------------------------------------------------------------------------------------------------
Topic: Math based - Excel Sheet Column Number - https://lnkd.in/g2JKSqZK
Code-
class Solution {
public int titleToNumber(String columnTitle) {
int ans = 0;
for (int i = 0; i < columnTitle.length(); ++i) {
ans = ans * 26 + (columnTitle.charAt(i) - 'A' + 1);
}
return ans;
}
}