ARTS-第三周挑战

  1. Algorithm:每周至少做一个 leetcode 的算法题

    swap nodes(链表两两交换结点)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode swapPairs(ListNode head) {
if(head == null) return head;
return swapPairs(head,head.next);
}


public ListNode swapPairs(ListNode currentNode, ListNode nextNode) {
if (currentNode == null) {
return currentNode;
}

if (nextNode == null) {
return currentNode;
}
ListNode newHead,changedNextNode,newCurrent;

changedNextNode = swapNode(currentNode, nextNode);
newHead = nextNode;

newCurrent = changedNextNode.next;
if (newCurrent == null || newCurrent.next == null) {
return newHead;
}

swapPairs(changedNextNode, newCurrent, newCurrent.next);

return nextNode;
}

public void swapPairs(ListNode prevNode,ListNode currentNode , ListNode nextNode){
if(currentNode ==null || nextNode == null) return ;

ListNode changeLastNode;
changeLastNode = swapNode(prevNode,currentNode,nextNode);

prevNode = changeLastNode;
currentNode = changeLastNode.next;
if(currentNode == null)
return ;
nextNode = changeLastNode.next.next;

swapPairs(prevNode,currentNode,nextNode);
}

public ListNode swapNode(ListNode prev,ListNode currentNode ,ListNode next){
ListNode tempNode;

tempNode = next.next;
next.next = currentNode;
currentNode.next = tempNode;
prev.next = next;

return currentNode;
}

public ListNode swapNode(ListNode currentNode,ListNode nextNode)
{
ListNode temp;

temp = nextNode.next;
nextNode.next = currentNode;
currentNode.next = temp;

return currentNode;
}
}
  1. Review:阅读并点评至少一篇英文技术文章

    为什么你应该学习go语言

看下来的好处,我认为是,go天生适合于多核心,多线程的操作环境,内存开销相较于java创建一个thread小太多,并且线程之间的通信困难,用goroutine,内存消耗少,更容易编程使用

  1. Tip:学习至少一个技术技巧

    vim常用快捷键
  1. Share:分享一篇有观点和思考的技术文章

    架构设计的目的