首页 > 其他 > 详细

Complete The Pattern #1

时间:2015-07-01 23:20:41      阅读:284      评论:0      收藏:0      [点我收藏+]

Complete The Pattern #1

Task:

You have to write a function pattern which creates the following pattern upto n number of rows.

  • If the Argument is 0 or a Negative Integer then it should return ""

Pattern:

1
22
333
....
.....
nnnnnn

Note: There are no spaces in the pattern

Hint: Use \n in string to jump to next line

 

无形装逼最为致命,居然喜欢上用Linq了

using System;
using System.Linq;

public class Kata
{
  public string Pattern(int n)
  {
    // Happy Coding ^_^
     string result = string.Empty;
            if (n > 0)
            {
                result = string.Join(Environment.NewLine, Enumerable.Range(1, n).Select(item => string.Join(string.Empty, Enumerable.Repeat(item, item))));
            }
            return result;
  }
}

 

Complete The Pattern #1

原文:http://www.cnblogs.com/chucklu/p/4614633.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!