javascript-简单工厂两种达成形式

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

 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          }

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

简简单单工厂笔记
 两种办法:
 第一种:通过实例化对象创立
 第三种:通过创设一个新对象然后卷入增强其品质和法力来落到实处
 差别性:前一种通过类创造的
对象,假如那么些类继承同一个父类,他们父类原型上的章程是足以共用的;后一种通过寄生形式开创的靶子都是一个新的民用,所以她们的不二法门就不能够共用了
 第一种和第两种都 以生产足球、篮球、网球为例子
 第一种办法

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

 

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

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

先是种简易工厂测试代码

Read the leetcode question and solutions:

1          //第一种测试
2          var football=ballFactory("football");
3          console.log(football.intro);
4          football.getMember();
5          football.getBallSize();

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

 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          }
  1. All 158 leetcode algorithm implementation in git hub:

其次种简易工厂测试

blog of a facebook programmer working on leetcode questions:

第三种简单工厂

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

  1.  binary tree
  1. Leetcode using C#

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

  1. Reverse nodes in k group

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

August 2, 2015

http://zzk.cnblogs.com/ 用”找一找”, 花了几个钟头, 找出相比好的Leetcode博客.

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

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

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

  1. Find lowest common ancestor in binary tree:

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