Giter Site home page Giter Site logo

offer-algorithm's People

Contributors

jchappytime avatar

Watchers

 avatar  avatar

offer-algorithm's Issues

乘积数组分析

1.关于乘积数组的分析需要再细化;
2.给出其他解决方案。

第3题:非递归解法分析

增加非递归解法的分析:
1.当n=1与n=2时,f(n) =1;
所以设置arr = [1, 1];
2. 当n >2时循环遍历,将值push到数组arr中
arr.push(arr[n-1] + arr[n-2]);

【数组】求2个数组的交集

  • 使用hash表的方式
intersection() {
    const num1 = [1, 2, 3, 4, 5, 6];
    const num2 = [5, 6, 6, 8, 10, 12];
    let result = [];
    let hashMap = {};

    for (let i = 0; i < num1.length; i++) {
      if (!hashMap[num1[i]]) {
        hashMap[num1[i]] = true;
      }
    }
    for (let j = 0; j < num2.length; j++) {
      if (hashMap[num2[j]]) {
        result.push(num2[j]);
        hashMap[num2[j]] = false;
      }
    }

    return result;
  }
  • 思路解析
  1. 首先遍历第一个数组,将数组中的值作为hash表的key,value设置为true;
  2. 遍历第二个数组,判断num2数组中的数字是否在hash表中,如果在则push到result中,并将其value设置为false.

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.