diff options
Diffstat (limited to 'basic_calculator.rs')
-rw-r--r-- | basic_calculator.rs | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/basic_calculator.rs b/basic_calculator.rs deleted file mode 100644 index d33a18c..0000000 --- a/basic_calculator.rs +++ /dev/null @@ -1,29 +0,0 @@ -struct Solution; - -impl Solution { - pub fn calculate(s: String) -> i32 { - let mut sp: Vec<i32> = Vec::new(); - let (mut ans, mut num, mut sign) = (0, 0, 1); - sp.push(sign); - for ch in s.chars() { - match ch { - ' ' => {} - '+' | '-' => { - ans += num * sign; - sign = sp.last().unwrap() * if ch == '+' {1} else {-1}; - num = 0; - } - '(' => {sp.push(sign);} - ')' => {sp.pop();} - _ => {num * 10 + (ch as i32 - '0' as i32)} - }; - } - ans += num * sign; - ans - } -} - -fn main() { - let s = String::from("1 + 1"); - print!("{}", Solution::calculate(s)); -} |