浏览代码

Another problem done, been a while

master
Lachlan Jacob 5 年前
父节点
当前提交
a7babbf899
共有 3 个文件被更改,包括 48 次插入0 次删除
  1. 15
    0
      problems/441/main.c
  2. 28
    0
      problems/441/problem.txt
  3. 5
    0
      problems/441/run.sh

+ 15
- 0
problems/441/main.c 查看文件

@@ -0,0 +1,15 @@
#include <stdio.h>

int arrangeCoins(int n){
int count = 0;
while (n >= count + 1) {
n -= ++count;
}
return count;
}

int main() {
printf("Expected: 3\n");
printf("Got: %d\n", arrangeCoins(8));
return 0;
}

+ 28
- 0
problems/441/problem.txt 查看文件

@@ -0,0 +1,28 @@
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.

Given n, find the total number of full staircase rows that can be formed.

n is a non-negative integer and fits within the range of a 32-bit signed integer.

Example 1:

n = 5

The coins can form the following rows:
¤
¤ ¤
¤ ¤

Because the 3rd row is incomplete, we return 2.

Example 2:

n = 8

The coins can form the following rows:
¤
¤ ¤
¤ ¤ ¤
¤ ¤

Because the 4th row is incomplete, we return 3.

+ 5
- 0
problems/441/run.sh 查看文件

@@ -0,0 +1,5 @@
#!/bin/bash

gcc -o main main.c
./main
rm main

正在加载...
取消
保存