Struct Algorithm

Source
pub struct Algorithm {}

Implementations§

Source§

impl Algorithm

Source

pub fn gcd_of_strings(str1: String, str2: String) -> Option<String>

求两个字符串的最大公约字符串

§Arguments
  • str1 - 第一个字符串
  • str2 - 第二个字符串
§Examples
use rust_algorithm::Algorithm;
let result = Algorithm::gcd_of_strings(String::from("ABCABCABC"), String::from("ABC"));
assert_eq!(result.unwrap(), "ABC");
Examples found in repository?
examples/main.rs (line 4)
3fn main () {
4  let result = Algorithm::gcd_of_strings(String::from("ABCABC"), String::from("ABC"));
5  println!("{}", result.unwrap());
6}
Source

pub fn gcd(int1: i32, int2: i32) -> i32

求两个数的最大公约数(greatest common divisor)

§Arguments
  • int1 - 第一个数
  • int2 - 第二个数
§Examples
use rust_algorithm::Algorithm;
let result = Algorithm::gcd(8, 4);
assert_eq!(result, 4);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.