美文网首页
ARTS挑战-第一周

ARTS挑战-第一周

作者: 陈_振 | 来源:发表于2019-03-23 22:56 被阅读0次

Algorithm

Leetcode-283

给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。

示例:

输入: [0,1,0,3,12]
输出: [1,3,12,0,0]
说明:

必须在原数组上操作,不能拷贝额外的数组。
尽量减少操作次数。


class Solution {
public:
    void moveZeroes(vector<int>& nums) {

        vector<int> notZeroArray;

        for(int i = 0 ; i < nums.size() ; i++) {
            if(nums[i]) {
                notZeroArray.push_back(nums[i]);
            }
        }
        
        for(int i = 0 ; i < notZeroArray.size() ; i++) {
            nums[i] = notZeroArray[i];
        }
        
        for(int i = notZeroArray.size() ; i < nums.size() ; i++) {
            nums[i] = 0;
        }
    }
};

Review

NSHashTable&NSMapTable

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

  1. workhorse
    adj. 工作重的;吃苦耐劳的
    美 ['wə:khɔ:s]
    eg: NSArray are the workhorse collection classes of Foundation.
    (这里可翻译为主要的)

  2. general-purpose
    adj. 多用途的;一般用途的
    英 ['dʒenərəl'pə:pəs]
    eg: use a more general-purpose solution.

  3. breaking assumption
    n. 打破假设,不符合预期
    eg: For NSSet and NSDictionary, the breaking assumption was in the memory behavior when storing objects in the collection.

Tip

参考文章:
nil/Nil/NSNull

1.png

NULL:C类型的指针(void *),指针变量,空指针。

nil:是一个对象类型指针,指向nothing。

Nil:是一个类对象的指针,指向nothing。

NSNull :是一个OC对象,用来表达空的单例对象。常用于存放在容器类对象中(NSArray,NSDictionary)

NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
mutableDictionary[@"someKey"] = [NSNull null]; // Sets value of NSNull singleton for `someKey`
NSLog(@"Keys: %@", [mutableDictionary allKeys]); // @[@"someKey"]

Share

你可以不自己造轮子,但应该了解轮子的结构,而且越详尽越好,这就是程序员的自我修养吧。 ----《程序员的自我修养》

CPU体系结构,汇编,C语言(包括C++)和操作系统,永远都是编程大师们的护身法宝。 ----《《程序员的自我修养》》

珍惜在学校的最后两三个月。

相关文章

  • ARTS挑战-第一周

    Algorithm Leetcode-283 Review NSHashTable&NSMapTable 本文的单...

  • ARTS打卡第一周

    ARTS打卡第一周 Algorithm:每周至少做一个 leetcode 的算法题 542. 01 矩阵 Revi...

  • ARTS第一周

    关于ARTS的说明请看这里 Algorithm 本周的算法题是Reverse Integer,由于是刚开始,选择了...

  • ARTS第一周

    Algorithm leetcode301(https://leetcode.com/problems/remov...

  • 第一周-ARTS

    Algorithm: http://poj.org/problem?id=1001 解法思路: 利用一个字符数组来...

  • 第一周ARTS

    Algorithmic 返回x的平方根,第一次刷leetcode,代码的执行时间和内存占用清楚显示。 https:...

  • ARTS第一周

    Algorithm。主要是为了编程训练和学习。每周至少做一个 leetcode 的算法题(先从Easy开始,然后再...

  • ARTS第一周

    1.Algorithm:压缩字符串 2.Review:supervisord的使用 3.Tip:Lua中迭代的使用...

  • ARTS挑战-第二周

    Algorithm Leetcode-75 Review File System Programming Guid...

  • ARTS挑战第五周

    Algorithm Review Tip 关于选择 面对多个选择,展望一下各个选择的最终结果,在结果上进行斟酌。 ...

网友评论

      本文标题:ARTS挑战-第一周

      本文链接:https://www.haomeiwen.com/subject/tjievqtx.html