This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn equal_ignoring_case(a: &str, b: &str) -> bool { | |
a.chars().flat_map(char::to_lowercase).eq(b.chars().flat_map(char::to_lowercase)) | |
} | |
fn starts_with_ignoring_case(s: &str, prefix: &str) -> bool { | |
let mut s = s.chars().flat_map(char::to_lowercase); | |
let mut prefix = prefix.chars().flat_map(char::to_lowercase); | |
while let Some(s_ch) = s.next() { | |
match prefix.next() { | |
Some(p_ch) => if s_ch != p_ch { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env::var("RABBIT_MQ_PORT").ok().and_then(|x| x.parse::<u32>().ok()).unwrap_or(5672) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//[dependencies] | |
//serde_json = "1.0" | |
use serde_json::Value; | |
use std::collections::{HashMap, HashSet}; | |
const FILE_BUFFER_SIZE: usize = 50000; | |
//source data | |
#[derive(Default)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn plus() { | |
let a = String::from("a"); | |
let b = String::from("b"); | |
assert_eq!(a + &b, "ab"); | |
} | |
#[test] | |
fn plus_assign() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let points = vec![ | |
Point { x: (-1.0, 1.0), y: 1.0 }, | |
Point { x: (0.0, -1.0), y: -1.0 }, | |
Point { x: (10.0, 1.0), y: 1.0 } | |
]; | |
let result = Solution::regress(&points); | |
println!("result {:#?}", result); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(box_syntax)] | |
// Framework | |
trait Bind<S: ?Sized> { | |
fn bind(&mut self, service: Box<S>); | |
fn get(&self) -> &Box<S>; | |
fn get_mut(&mut self) -> &mut Box<S>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Solution { | |
pub fn my_atoi(str: String) -> i32 { | |
let mut started = false; | |
let mut result: i32 = 0; | |
let mut sign: i32 = 1; | |
for b in str.into_bytes() { | |
if b == 32 { | |
if started { | |
break; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Solution { | |
pub fn is_valid(s: String) -> bool { | |
let opening = "([{"; | |
let closing = ")]}"; | |
let mut par: Vec<usize> = vec![]; | |
for c in s.chars() { | |
match opening.find(c) { | |
Some(i) => { | |
par.push(i); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::iter::FromIterator; | |
impl Solution { | |
pub fn divide(dividend: i32, divisor: i32) -> i32 { | |
let dividend_p = (dividend as i64).abs(); | |
let divisor_p = (divisor as i64).abs(); | |
let div_chars: Vec<char> = dividend_p.to_string().chars().collect(); | |
let mut result_chars = Vec::new(); | |
let mut i: usize = 0; | |
let mut part_div_chars = Vec::new(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let result = Solution::roman_to_int("MCMXCVI"); | |
println!("{}", result); | |
} | |
struct Solution {} | |
impl Solution { | |
pub fn roman_to_int(s: String) -> i32 { | |
let states = vec![('-', 'I', 1), |