摘要: 力扣链接:https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/ 题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。 eg. 输入: [7, 阅读全文
posted @ 2021-04-19 00:50 studystudyxinxin 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 1. class的基本使用 class Student { constructor(name, number){ this.name = name; this.number = number; } sayHi(){ console.log( `姓名 ${this.name} , 学号 ${this. 阅读全文
posted @ 2020-10-27 07:09 studystudyxinxin 阅读(336) 评论(0) 推荐(0) 编辑
摘要: 力扣链接:https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/ 题目描述 0,1,,n-1这n个数字排成一个圆圈,从数字0开始,每次从这个圆圈里删除第m个数字。求出这个圆圈里剩下的最后一个 阅读全文
posted @ 2020-07-19 23:34 studystudyxinxin 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 力扣链接:https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/ 题目描述 请定义一个队列并实现函数 max_value 得到队列里的最大值,要求函数max_value、push_back 和 pop_front 的均摊时间复杂度都是 阅读全文
posted @ 2020-07-17 23:02 studystudyxinxin 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 原型链 假借构造函数 组合继承 原型式(Prototypal) 寄生式 组合寄生式 主要形式 subType.prototype = new SuperType() SuperType.call(this) subType.prototype = new SuperType() + SuperTyp 阅读全文
posted @ 2020-07-15 11:13 studystudyxinxin 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 普通的组合继承模式中,我们两次调用了父类的构造函数,导致父类的实例属性在子类实例和子类原型上同时存在。主要问题在于在第一次调用时,我们将一个父类实例作为子类的原型,使得父类的实例属性不必要的被复制到了子类原型上。 理想的效果是,只将子类原型的[[Prototype]]隐式属性指向父类原型,不在原型上 阅读全文
posted @ 2020-07-15 08:30 studystudyxinxin 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 基本模式 原型式继承(Prototypal Inheritance)和工厂模式的结合,用一个函数先创建以父类为原型的对象,再为这个对象添加需要的子类属性及方法。最后直接返回这个对象。 function object(o){ function F(){} F.prototype = o; return 阅读全文
posted @ 2020-07-15 08:03 studystudyxinxin 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 基本形式 //创建一个以o为原型的对象 function object(o){ function F(){} F.prototype = o; return new F(); } let person = { name: "Jack", friends: ["Ann", "Bob"] }; let 阅读全文
posted @ 2020-07-15 07:41 studystudyxinxin 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 基本形式 通过原型链继承原型属性及方法,通过假借构造函数继承实例属性及方法。 function SuperType(name){ this.name = name; this.colors = ["red", "blue"]; } SuperType.prototype.sayName = func 阅读全文
posted @ 2020-07-15 07:02 studystudyxinxin 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 基本形式 function Person(name){ this.name = name; } Person.prototype.sayHi = function(){ console.log(this.name); } function Student(name, mark){ Person.ca 阅读全文
posted @ 2020-07-15 06:36 studystudyxinxin 阅读(95) 评论(0) 推荐(0) 编辑