Skip to content

Instantly share code, notes, and snippets.

/// 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 {
@frol
frol / qq.rs
Created February 28, 2019 22:26
// 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;
}
}
@frol
frol / qq.kt
Last active February 28, 2019 22:18
// 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()
}
}
@frol
frol / auto-rc.rs
Created January 7, 2019 23:01
This is just an abuse of Not operator to get a shortcut syntax
#[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())
}
}
#![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);