Sixth Week's ARST

ARST

A

Leetcode27-- Remove Element
题目要求
Given an array nums and a value val, remove all instances of that value in-place and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.
Example 1:

Given nums = [3,2,2,3], val = 3,

Your function should return length = 2, with the first two elements of nums being 2.

It doesn't matter what you leave beyond the returned length.

Example 2:

Given nums = [0,1,2,2,3,0,4,2], val = 2,

Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4.

Note that the order of those five elements can be arbitrary.

It doesn't matter what values are set beyond the returned length.

C++编写

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int len=nums.size();       
        int i=-1;
        for(int j=0;j<len;j++)
        //将等于val的值全部移到末尾
        {
            if(nums[j]!=val)    swap(nums[++i], nums[j]);   
        }        
        return i+1 ;
    }
};

这道题还是比较简单,就是要注意条件所说的不要为另一个数组分配额外的空间,等于直接在原数组上进行操作

S

特斯拉自动驾驶汽车
周一,特斯拉举办了一场重大活动,展示了该公司在全自动驾驶技术方面取得的令人瞩目的进展。该公司展示了一种新的神经网络计算机。马斯克预测,只需要六个月的时间,软件就可以变得足够可靠,不再需要人工监督。到2020年底,马斯克预计特斯拉将拥有数千辆特斯拉汽车,为优步式出租车服务的乘客提供无人驾驶的乘车服务。现在确实科技发展得很快,特斯拉也在研制一种芯片用于汽车的无人驾驶,这其中就需要神经网络和深度学习方面的技术,所以编程几乎是无处不在,以前说学好数学和英语走到哪里都不怕,现在我觉得还可以加上一个编程。

R

本周浅谈一下C++中sizeof()、size()、length()、strlen()以及vector容器中size()计算长度的区别
1、sizeof()是一个运算符获取类型原形所占用的字节长度
例如:sizeof(int)=4;sizeof(double)=8;sizeof(char)=1;
2、strlen()是计算字符串长度的函数
Example

char a[]="hello";//字符数组
strlen(a)=5;//字符长度

3、size()与length()均为string类的成员函数
Example

string a="hello";
a.length()=5;
a.size()=5;

4、STL容器中的vector是一个顺序行容器。相当于数组,在一块连续内存上存储数据,其大小可以不预先给定,自动扩展,一般可以将其作为动态数组使用。
一般用使用vector容器定义数组,然后调用size()返回数组长度,vector容器中没有length()这个用法

T

这周的C++课程教授了类的特殊成员,其中个人来说对运算符的重载感觉没能理解,网上找了一篇文章解释这个内容,同时该网站有关C++的很多问题也都有相关教程
C++学习教程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值