Leetcode study time

August 2, 2015

简言之工厂笔记
 三种办法:
 第一种:通过实例化对象创设
 第三种:通过成立一个新对象然后卷入增强其性能和意义来贯彻
 差距性:前一种通过类创制的
对象,如果那几个类继承同一个父类,他们父类原型上的章程是足以共用的;后一种通过寄生格局开创的目的都是一个新的村办,所以她们的不二法门就不能够共用了
 第一种和第三种都 以生育足球、篮球、网球为例子
 第一种办法

http://zzk.cnblogs.com/ 用”找一找”, 花了多少个时辰, 找出比较好的Leetcode博客.

 1         var Basketball = function(){
 2              this.intro = '篮球盛行于美国';
 3          }
 4          Basketball.prototype={
 5              getMember:function(){
 6                  console.log("每个队伍需要5名队员")
 7              },
 8              getBallSize:function(){
 9                  console.log("篮球很大");
10              }
11          }
12          var Football = function(){
13              this.intro="足球在全世界范围类很流行";
14          }
15          Football.prototype={
16              getMember:function(){
17                  console.log("每个队伍需要11名队员")
18              },
19              getBallSize:function(){
20                  console.log("足球很大");
21              }
22          }
23          var Tennis = function(){
24              this.intro="每年有很多网球系列赛";
25          }
26          Tennis.prototype={
27              getMember:function(){
28                  console.log("每个队伍需要1名队员")
29              },
30              getBallSize:function(){
31                  console.log("网球很小");
32              }
33          }
34          
35          //第一种球工厂
36          var ballFactory=function(name){
37              switch(name){
38                  case 'basketball':
39                    return new Basketball();
40                  case 'football':
41                    return new Football();
42                  case 'tennis':
43                    return new Tennis();
44              }
45          }

Read the leetcode question and solutions:

第一种不难工厂测试代码

  1. Find lowest common ancestor in binary tree:
1          //第一种测试
2          var football=ballFactory("football");
3          console.log(football.intro);
4          football.getMember();
5          football.getBallSize();

blog of a facebook programmer working on leetcode questions:

第三种不难工厂

递归版本:空间O(1),时间O(n)

 1          //第二种
 2          function createBall(type,intro,num,ballsize){
 3              var o = new Object();
 4              o.intro = intro;
 5              o.num = num;
 6              o.ballsize = ballsize;
 7              o.getMember = function(){
 8             //公共方法getNember
 9                  console.log("每个队伍需要"+this.num+"名队员");
10              }
11              o.getBallSize = function(){
12             //公共方法getBallSize
13                  console.log(this.ballsize);
14              }
15              if(type == 'basketball'){
16                  //篮球差异部分
17              }
18              if(type=="football"){
19                  //足球差异部分
20              }
21              if(type=="tennis"){
22                  //网球差异部分
23              }
24              return o;
25          }

http://www.cnblogs.com/chkkch/archive/2012/11/26/2788795.html

第二种简易工厂测试

Try it myself and compare to solutions in my blog:
http://juliachencoding.blogspot.ca/2015/07/leetcode-lowest-common-ancestor-in.html

         //第二种测试
         var football2=createBall("football","足球在全世界范围类很流行",11,"足球很大");
         console.log(football2.intro);
         football2.getMember();
         football2.getBallSize();
  1. Reverse nodes in k group

 

http://www.cnblogs.com/lichen782/p/leetcode_Reverse_Nodes_in_kGroup.html

http://www.cnblogs.com/grandyang/p/4606710.html

  1.  binary tree

http://www.cnblogs.com/wwwjieo0/p/3891037.html

  1. All 158 leetcode algorithm implementation in git hub:

http://coolshell.cn/articles/1870.html

Leetcode solution on git hub (use this one more often, best answer,
author profile: http://coolshell.cn/haoel)

https://github.com/haoel/leetcode/tree/master/algorithms

  1. Leetcode using C#

https://github.com/xisuogu/LeetSharp/tree/master/LeetSharp

  1. One more to read

http://blog.csdn.net/u014674776/article/category/2296455

麻烦了多少个钟头, 总算可以飞往放松,打打网球,准备后天登山了!