码迷,mamicode.com
首页 > 其他好文 > 详细

Complete The Pattern #1

时间:2015-07-01 23:23:50      阅读:238      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!