Kaynağa Gözat

Another problem done, been a while

master
Lachlan Jacob 5 yıl önce
ebeveyn
işleme
a7babbf899
3 değiştirilmiş dosya ile 48 ekleme ve 0 silme
  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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

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

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

Loading…
İptal
Kaydet