[−][src]Struct leetcode_for_rust::cd0933_number_of_recent_calls::RecentCounter
Solutions
Approach 1: Queue
-
Time complexity: O(n)
-
Space complexity: O(1)
-
Runtime: 40 ms
-
Memory: 5.4 MB
use std::collections::VecDeque; #[derive(Default)] struct RecentCounter { pings: VecDeque<i32>, } /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ impl RecentCounter { fn new() -> Self { Default::default() } fn ping(&mut self, t: i32) -> i32 { self.pings.push_back(t); while t - *self.pings.front().unwrap() > 3000 { self.pings.pop_front(); } self.pings.len() as i32 } } /** * Your RecentCounter object will be instantiated and called as such: * let obj = RecentCounter::new(); * let ret_1: i32 = obj.ping(t); */
Auto Trait Implementations
impl Sync for RecentCounter
impl Send for RecentCounter
impl Unpin for RecentCounter
impl RefUnwindSafe for RecentCounter
impl UnwindSafe for RecentCounter
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,