2022-07-07 惨淡的蔚来面试

1.找错

#include<iostream>
using namespace std;
class A{
public:
virtual void a()=0;
A(){
 cout<<"A ";
}
};
class B: public A
{
public:
B(){
 cout<<"B ";
} 
};

int main(){
    A *a=new B();

return 0;
}

2. 

class String
{
public:
    String(const char *str = NULL){ // 普通构造函数
      if(!str) {
           m_data=nullptr;
        m_data = '\0'
        return;
      }
      len = strlen(str)
      int len=0;
      const char* p=str;
      while(p){
           len++;
        p++;
      }
      len++;

      m_data=malloc(len*sizeof(char));
      const char* q=m_data;
      strcpy()
      p=str;
      while(p){
        *q++=*p++; 
      }
      *q='\0';
    }

    String(const String &other){ // 拷贝构造函数(深拷贝 )
       free(m_data);
          m_data=other.m_data;
    }

    ~ String(void){ // 析构函数
         free(m_data); 
    }

      String & operator =(const String &other){ 
          return String(other.m_data);

    }
private:
    char *m_data; // 用于保存字符串
};



string str1=  "helloworld";
string str2 = "aaaa"

  str2 = str1;

3. 

class String(
  private:
  String(){
    data=malloc(1);
    *data='\0';
  }
  char* data;

  ~String(){
    free(data); 
  }

  static bool initialized=false;
  static mutex lock;
  static String* instance;

  public:


  static String getSingleObject(){

    // 加锁
    if(initialized){
     return *this; 
    }
    // 解锁

    this->String();
    initialized=true;

    return *this;
  }

  };

  String::get

  4.

 题目描述:
主要元素
数组中占比超过一半的元素称之为主要元素。给定一个整数数组,找到它的主要元素。若没有,返回-1。
示例 1:
输入:[1,2,5,9,5,9,5,5,5]输出:5

示例 2:
输入:[3,2]输出:-1

示例 3:
输入:[2,2,1,1,1,2,2]输出:2


int findMoreThanHalf(vector<int> v){
        int a=-1;
    int counter=0;
    for(const auto& i:v){
        if(i==a) counter++;
      else {
          counter--;
        if(counter<0){
            a=i;
          counter=1;
        }
      }
    }

        return counter?a:-1;
}

图片说明

图片说明

正式批做了笔试,没消息。

#蔚来面试##面试##23秋招##23届提前批#
全部评论
都是典型的算法题啊,看来还是要刷题
点赞 回复 分享
发布于 2022-08-27 23:09 陕西

相关推荐

小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务