Selaa lähdekoodia

Latest May problem

master
Lachlan Jacob 5 vuotta sitten
vanhempi
commit
13bc63cf96
3 muutettua tiedostoa jossa 36 lisäystä ja 0 poistoa
  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 Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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 Näytä tiedosto

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

rustc main.rs
./main
rm main

Loading…
Peruuta
Tallenna