ARTS挑战-第二周

Algorithm

Leetcode-75

给定一个包含红色、白色和蓝色,一共 *n *个元素的数组,**[原地](https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95)**对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。

此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。

**注意:**
不能使用代码库中的排序函数来解决这道题。

**示例:**

**进阶:**

*   一个直观的解决方案是使用计数排序的两趟扫描算法。
    首先,迭代计算出0、1 和 2 元素的个数,然后按照0、1、2的排序,重写当前数组。
*   你能想出一个仅使用常数空间的一趟扫描算法吗?


class Solution {
public:
    void sortColors(vector &nums) {

        int zero = -1;        
        int two = nums.size(); 
        for(int i = 0 ; i < two ; ) {
            if(nums[i] == 1) {
                 i++;
            }
            else if (nums[i] == 2) {
                 two--;
                 swap( nums[i] , nums[two]);
            }
            else {
                 zero++;
                 swap(nums[zero] , nums[i]);
                 i++;
            }
        }
    }
};

Review

File System Programming Guide

本文的单词摘自Apple的官方文档,记录自己看文档时遇到的生词。

  1. overarching
    adj.首要的
    美 [,əuvə'rɑ:tʃiŋ]
    eg: the overarching goal is to make sure that the user’s files remain easily

  2. tampering
    v.篡改
    [[ˈtæmpərɪŋ]]
    eg: To prevent tampering, the bundle directory is signed at installation time.

  3. segregated
    adj. 被隔离的
    美 ['seɡriɡeitid]
    eg: files are segregated into "documents" and data.

  4. encrypted
    v. 把…编码;把…加密
    eg: Files Can Be Encrypted On Disk.

  5. decryption
    n. [通信] 解密
    [di:'kripʃən]
    eg: the system creates a decryption key that allows the app to access its encrypted files.

  6. robustness
    n.[计] 稳健性;
    美 [ro'bʌstnɪs]
    eg: Synchronization Ensures Robustness in Your File-Related Code

  7. simultaneously
    adv. 同时地
    美 [saɪməl'tenɪəsli]
    eg: For most tasks, it is safe to use the default NSFileManager object simultaneously from multiple background threads.

  8. concatenating
    v. 把…连在一起
    eg: For most URLs, you build the URL by concatenating directory and file names together using the appropriate NSURL methods until you have the path to the item.

Tip

git log

显示当前分支的记录

git log --all

显示所有分支的记录

git log --all --graph

图形化的形式显示所有分支

git log -n2/git log --oneline --all -n2/...

查看最近两次的提交。

git checkout [comit_id]

可以基于某次commit分离头指针,在HEAD detached from comit_idcommit的记录不会被git作为分支记录,如果此时切换回其他分支,那么在分离头指针上的操作有可能被丢弃。除非通过git branch [new-branch-name] [commit-id]显示为分离头指针创建一个分支。

git diff [commit-id-one] [commit-id-another]

也可以使用git diff HEAD HEAD~1 比较当前commit和上次commit。

修改最新的commit message

git commit --amend

修改老旧的commit message

git rebase -i [需要调整的commit的parent commit id]

把将要修改的commit前的pick改为reword或者r。

把连续的多个commit整理成一个

git rebase -i [需要调整的commit的parent commit id]

把将要合并的commit前的pick改为squash或者s。

Share

  • 对于目标有有一个清晰的认识,可以帮你更加有效的安排自己的行为
  • 知道自己的目标,就更容易知道哪些事情重要哪些不重要。这会让高效公作,井然有序的目标更容易实现
  • 目标越详尽,明确,实现起来就越容易,结果的衡量也越容易
  • 对目标产生的结果要学会灵活变通,第一种办法不成功可以随时找到实现目标的新途径
  • 确定明确详尽的目标前问自己几个问题:我真正需要实现的目标是什么?我为什么要实现这个目标?如果我不这么做会出现什么情况?我必须采取的行动是什么?

你可能感兴趣的:(ARTS挑战-第二周)