GithubHelp home page GithubHelp logo

mmzhe / internet-recruiting-algorithm-problems Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lyricyang/internet-recruiting-algorithm-problems

0.0 1.0 0.0 374 KB

互联网公司招聘算法笔试题(详细解答)

License: MIT License

internet-recruiting-algorithm-problems's Introduction

公司招聘算法笔试题解答

license

公司 公司类型 招聘公众号 2018笔试题 2017笔试题 内推码
[√]网易 互联网 微信号:wangyizhaopin 2018 2017 222O01Q
网易游戏 互联网 微信号:gh_b8dad7e663af 2018 2017
网易有道 互联网 微信号:gh_8b7a5fdb804d 2018 2017
远景能源 互联网/能源 微信号:Envisioncn_recruit 2018 2017
今日头条 互联网 微信号:toutiaohr 2018 2017 JFWWNV7
拼多多 互联网 微信号:gh_42cd7f735d3d 2018 2017
[√]华为 互联网/通信 微信号:huaweizhaopin 2018 2017
招商银行信用卡中心 互联网/金融 微信号:cmbccjob 2018 2017
招银科技 互联网 微信号:gh_c84d54755c92 2018 2017
[√]携程 互联网 微信号:ctriphr 2018 2017
百度 互联网 微信号:talent_baidu 2018 2017
腾讯 互联网 微信号:QQjobs 2018 2017
阿里 互联网 微信号:gh_f764a77534dc 2018 2017
趋势科技 互联网 微信号:qushizhaopin 2018 2017
微软 互联网 微信号:joinmicrosoft 2018 2017
海康威视 互联网 微信号:HikivisionHR 2018 2017
美团点评 互联网 微信号:dianpinghr 2018 2017
中兴 互联网/通信 微信号:joinzte 2018 2017
小米 互联网 微信号:gh_249bb04444d7 2018 2017
VIVO 互联网 微信号:vivozhaopin 2018 2017
京东 互联网 微信号:jd_zhaopin 2018 2017
51信用卡 互联网 微信号:u51_hr 2018 2017
[×]大疆 互联网/通信 微信号:DJI_Recuitment 2018 2017
滴滴出行 互联网/通信 微信号: 2018 2017
唯品会 互联网/通信 微信号: 2018 2017
新浪 互联网/通信 微信号: 2018 2017
科大讯飞 互联网/通信 微信号: 2018 2017
CVTE 互联网/通信 微信号: 2018 2017
NVIDIA 互联网/通信 微信号: 2018 2017
[√]**银联 互联网/通信 微信号: 2018 2017 01202889
旷视科技 互联网/通信 微信号: 2018 2017
OPPO 互联网/通信 微信号: 2018 2017
汇顶科技 互联网/通信 微信号: 2018 2017

面试中手撕代码

1. 获取一个目录下的所有文件夹和文件,包括子文件夹和子文件

import java.io.File;
/*
 * 获取一个目录下的所有文件夹和文件,包括子文件夹和子文件 。
 * 并将文件夹和文件名称打印在控制台上面。并且要显示文件目录的层级
 * 注:运用了递归的算法。
 */
public class FilePath {
 
  public static void main(String[] args) {
    File dir=new File("/home/coding/workspace/python/");
    //File dir=new File("F:\\");
    //如果使用上述的盘符的根目录,会出现java.lang.NullPointerException
    //为什么?
    getAllFiles(dir,0);//0表示最顶层
  }
  //获取层级的方法
  public static String getLevel(int level)
  {
    //A mutable sequence of characters.
    StringBuilder sb=new StringBuilder();
    for(int l=0;l<level;l++)
    {
      sb.append("|--");
    }
    return sb.toString();
  }
  public static void getAllFiles(File dir,int level)
  {
    System.out.println(getLevel(level)+dir.getName());
    level++;
    File[] files=dir.listFiles();
    for(int i=0;i<files.length;i++)
    {
      if(files[i].isDirectory())
      {
        //这里面用了递归的算法
        getAllFiles(files[i],level);
      }
      else {
        System.out.println(getLevel(level)+files[i]);
      }	
    }		 
  }
}

2. 快速排序

public class QuickSort {
    public static void main(String[] args){
        int[] array = {1,1,8,8,11,34,55,23,65,24,67,4,5};
        for (int i:array) {
            System.out.print(i+" ");
        }
        System.out.println();
        quickSort(array,0,array.length-1);
        for (int i:array) {
            System.out.print(i+" ");
        }
        System.out.println();
    }

    private static void quickSort(int[] arr,int lo,int hi){
        if(arr==null||arr.length==0||lo>=hi) return;
        int loc=paritition(arr,lo,hi);
        quickSort(arr,lo,loc-1);
        quickSort(arr,loc+1,hi);
    }

    private static int paritition(int[] arr,int lo,int hi){
        int x=arr[lo];
        int i=lo;
        int j=hi;
        while(i<=j){
            while(i<=j&&arr[i]<=x) i++;
            while(j>=i&&arr[j]>x) j--;
            if(i<j){
                swap(arr,i,j);
                i++;
                j--;
            }
        }
        swap(arr,lo,j);
        return j;
    }

    private static void swap(int[] arr,int loc1,int loc2){
        if(loc1==loc2) return;
        int temp = arr[loc1];
        arr[loc1] = arr[loc2];
        arr[loc2] = temp;
    }
}

2. TopK

  • 最大的K个元素最小堆,最小的K个元素最大堆
public class TopK {
    public static void main(String[] args){
        int[] arr = { 1, 17, 3, 4, 5, 6, 7, 16, 9, 10};
        int K=4;
        int[] b=topK(arr,K);
        for (int i = 0; i < b.length; i++) {
            System.out.print(b[i]+",");
        }
    }
    private static int[] topK(int[] arr,int K){
        int[] top = new int[K];
        for (int i = 0; i < K; i++) {
            top[i]=arr[i];
        }
        buildHeap(top);
        for (int i = K ; i <arr.length ; i++) {
            if(arr[i]<top[0]){
                setTop(top,arr[i]);
            }
        }
        return top;
    }
    private static void buildHeap(int[] arr){
        int length = arr.length;
        for(int i=length/2-1;i>=0;i--){
            heapify(arr,i,length);
        }
    }
    private static void setTop(int[] arr,int val){
        arr[0]=val;
        heapify(arr,0,arr.length);
    }

    private static void heapify(int[] arr,int index,int length) {
        int left = 2 * index + 1;
        int right = 2 * index + 2;
        int largest = index;
        if (left < length && arr[left] > arr[largest])
            largest = left;
        if (right < length && arr[right] > arr[largest])
            largest = right;
        if (index != largest) {
            swap(arr, index, largest);
            heapify(arr, largest, length);
        }
    }
    public static void swap(int[] array, int a, int b) {
        int temp = array[a];
        array[a] = array[b];
        array[b] = temp;
    }
}
  • 快排**
public class TopKSort {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] array = { 9, 3, 1, 10, 5, 7, 6, 2, 8, 0 };
        TopK(array, 4);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + ", ");
        }
    }

    public static void TopK(int[] arr,int K){
        if(arr!=null&&arr.length>0){
            int low = 0;
            int high = arr.length-1;
            int index = partition(arr,low,high);
            while(index!=K-1){
                if(index>K-1){
                    high = index-1;
                    index=partition(arr,low,high);
                }
                if(index<K-1){
                    low=index+1;
                    index=partition(arr,low,high);
                }
            }
        }
    }

    private static int partition(int[] arr,int lo,int high){
        int x=arr[0];
        int i=lo+1;
        int j=high;
        while(i<=j){
            while(i<=j&&arr[i]<=x) i++;
            while(i<=j&&arr[j]>=x) j--;
            if(i<j){
                swap(arr,i,j);
                i++;
                j--;
            }
        }
        swap(arr,0,j);
        return j;
    }

    private static void swap(int[] arr,int loc1,int loc2){
        if(loc1==loc2) return;
        int temp = arr[loc1];
        arr[loc1] = arr[loc2];
        arr[loc2] = temp;
    }
}

说明

关于仓库

本仓库是笔者用于总结应届生在应聘互联网企业时遇到的各类算法题,欢迎大家贡献自己在解决笔试题的各种优秀的解题思路和参考代码!!!

关于转载

希望您在使用本仓库的内容时也能给出相应的引用链接。

internet-recruiting-algorithm-problems's People

Contributors

lyricyang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.