SLA-1

Source Code

java/lang/Integer.java

  • valueOf method is caching Integer from -128 to 127 (IntegerCache)
  • parseInt()
  • toString(int i, int radix)

Leetcode

https://leetcode.com/problems/swap-nodes-in-pairs/ 24. Swap node in pairs

Recursive solution, general idea is to reverse the current head with its next and the recursively swap the next pair of node. Clearly, when head is null or head.next is null, return the current head since there’s no need to swap at all.

The main body of this solution is to swap the current “head” with its next.

So the whole solution looks like this:

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
/**
* 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 swapPairs(ListNode head) {
// Base condition
if (head == null || head.next == null) return head;

// Swap
ListNode newHead = head.next;
head.next = newHead.next;
newHead.next = head;

// Recur
ListNode res = swapPairs(head.next);
head.next = res;
return newHead;
}
}

Architecture

https://www.infoq.com/articles/mtt-metrics-incident-response/?topicPageSponsorship=e46807b0-256d-42ac-9f43-14789284da53

  1. Set the alert on symptoms not causes.