說明
ARTS 是陳浩發(fā)起的高效學(xué)習(xí)計(jì)劃,包括四個部分:Algorithm/Review/Tip/Share
什么是ARST打卡計(jì)劃?
Algorithm
題目:反轉(zhuǎn)一個單鏈表。
code:
/*
* @lc app=leetcode.cn id=206 lang=cpp
*
* [206] 反轉(zhuǎn)鏈表
*/
// @lc code=start
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
if (head == nullptr) {
return head;
}
// store reverlist;
ListNode* list = new ListNode(head->val);
ListNode* temp = head;
while (temp->next != nullptr) {
temp = temp->next;
ListNode* oldHead = list;
list = new ListNode(temp->val);
list->next = oldHead;
oldHead = nullptr;
}
temp = nullptr;
return list;
}
};
Review
本周看了一篇Android MVVM的架構(gòu)文章。
ViewModel 和 LiveData:模式 + 反模式

Android MVVM架構(gòu)
本質(zhì)上所有的架構(gòu)都是一個思想,分類數(shù)據(jù),UI和業(yè)務(wù)邏輯。
文章中列出了幾條原則:
- Don’t let ViewModels (and Presenters) know about Android framework classes
- Keep the logic in Activities and Fragments to a minimum
- Avoid references to Views in ViewModels.
- Instead of pushing data to the UI, let the UI observe changes to it.
- Consider edge cases, leaks and how long-running operations can affect the instances in your architecture.
Tip
C++中為什么有拷貝和移動構(gòu)造函數(shù),JAVA中為什么沒有?
因?yàn)镃++對象中拷貝的對象(包含內(nèi)存地址),所以開銷比較大,因此移動構(gòu)造函數(shù),就是為了降低開銷而出現(xiàn)的,而Java中只拷貝了引用,開銷小。
Share
接下來打算寫車載系統(tǒng)的文章,本周正在構(gòu)思中...