Parcourir la source

Latest May problem

master
Lachlan Jacob il y a 5 ans
Parent
révision
13bc63cf96
3 fichiers modifiés avec 36 ajouts et 0 suppressions
  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 Voir le fichier

@@ -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 Voir le fichier

@@ -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 Voir le fichier

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

rustc main.rs
./main
rm main

Chargement…
Annuler
Enregistrer