Complete The Pattern #1

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;
  }
}

 

posted @ 2015-07-01 21:50  ChuckLu  阅读(428)  评论(0编辑  收藏  举报