Przeglądaj źródła

Latest May problem

master
Lachlan Jacob 5 lat temu
rodzic
commit
13bc63cf96
3 zmienionych plików z 36 dodań i 0 usunięć
  1. 17
    0
      problems/367/main.rs
  2. 14
    0
      problems/367/problem.txt
  3. 5
    0
      problems/367/run.sh

+ 17
- 0
problems/367/main.rs Wyświetl plik

@@ -0,0 +1,17 @@
pub fn is_perfect_square(num: i32) -> bool {
for x in 1..46341 {
let res = (x as i32).pow(2);
if res > num {
return false;
}
if res == num {
return true;
}
}
return false;
}

fn main() {
println!("Expected: true");
println!("Got: {}", is_perfect_square(16));
}

+ 14
- 0
problems/367/problem.txt Wyświetl plik

@@ -0,0 +1,14 @@
Given a positive integer num, write a function which returns True if num is a perfect square else False.

Note: Do not use any built-in library function such as sqrt.

Example 1:

Input: 16
Output: true

Example 2:

Input: 14
Output: false


+ 5
- 0
problems/367/run.sh Wyświetl plik

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

rustc main.rs
./main
rm main

Ładowanie…
Anuluj
Zapisz