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
| /// This is a direct line-by-line translation from C++ solution: | |
| /// https://github.com/LyashenkoGS/cpluplus_study/blob/master/test/Solution.cpp | |
| /// | |
| /// The point is to show that Rust can save your ass. | |
| struct Solution {} | |
| impl Solution { | |
| fn processParenthesis(stack1: &mut Vec<char>, item: char, openSign: char, closingSign: char) { | |
| if item == openSign { |
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
| // Simple | |
| fn array_manipulation_simple(n: usize, queries: &[(usize, usize, isize)]) -> isize { | |
| let mut checkpoints = vec![0; n]; | |
| for &(start, end, value) in queries { | |
| checkpoints[start - 1] += value; | |
| if end < n { | |
| checkpoints[end] -= value; | |
| } | |
| } |
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
| // Simple | |
| fun arrayManipulation(n: Int, queries: Array<Array<Int>>): Long { | |
| val checkpoints = Array<Long>(n, { 0 }) | |
| for ((start, end, value) in queries) { | |
| checkpoints[start - 1] += value.toLong() | |
| if (end < n) { | |
| checkpoints[end] -= value.toLong() | |
| } | |
| } |
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
| #[derive(Debug, Clone)] | |
| struct AutoRc<T>(pub std::rc::Rc<T>); | |
| impl<T: Clone> std::ops::Not for &AutoRc<T> { | |
| type Output = AutoRc<T>; | |
| fn not(self) -> Self::Output { | |
| AutoRc(self.0.clone()) | |
| } | |
| } |
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(async_await, await_macro, futures_api)] | |
| use futures::task::SpawnExt; | |
| use futures::io::{AsyncReadExt, AsyncWriteExt, AllowStdIo}; | |
| use romio::TcpStream; | |
| async fn send_and_receive_request(id: i32) { | |
| eprintln!("BEGIN send_and_receive_request #{}", id); |
NewerOlder