Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打印杨辉三角的前 n 行 #60

Open
nmsn opened this issue May 18, 2023 · 1 comment
Open

打印杨辉三角的前 n 行 #60

nmsn opened this issue May 18, 2023 · 1 comment
Labels

Comments

@nmsn
Copy link
Contributor

nmsn commented May 18, 2023

No description provided.

@nmsn nmsn added the 算法 label May 18, 2023
@nmsn
Copy link
Contributor Author

nmsn commented May 18, 2023

function printYangHuiTriangle(n) {
  let triangle = [];
  for (let i = 0; i < n; i++) {
    triangle[i] = [];
    for (let j = 0; j <= i; j++) {
      if (j === 0 || j === i) {
        triangle[i][j] = 1;
      } else {
        triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
      }
    }
    console.log(triangle[i].join(" "));
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant