leetcode 224. Basic Calculator

leetcode
九章

题目描述

Implement a basic calculator to evaluate a simple expression string.

The expression string may contain open ( and closing parentheses ), the
plus + or minus sign -, non-negative integers and empty spaces .

Example 1:

Input: "1 + 1"
Output: 2

Example 2:

Input: " 2-1 + 2 "
Output: 3

Example 3:

Input: "(1+(4+5+2)-3)+(6+8)"
Output: 23

Note:

  • You may assume that the given expression is always valid.
  • Do not use the eval built-in library function.

展开:

Difficulty: Hard

答案



leetcode 739. Daily Temperatures

leetcode
九章

题目描述

Given a list of daily temperatures T, return a list such that, for each day
in the input, tells you how many days you would have to wait until a warmer
temperature. If there is no future day for which this is possible, put 0
instead.

For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].

Note: The length of temperatures will be in the range [1, 30000]. Each
temperature will be an integer in the range [30, 100].

Tags: Hash Table, Stack

Difficulty: Medium

答案

LeetCode 图解 | 739.每日温度 - 每日温度 - 力扣(LeetCode)



leetcode 844. Backspace String Compare

leetcode
九章

题目描述

Given two strings S and T, return if they are equal when both are typed
into empty text editors. # means a backspace character.

Example 1:

Input: S = "ab#c", T = "ad#c"
Output: true
**Explanation** : Both S and T become "ac".

Example 2:

Input: S = "ab

答案



leetcode 155. Min Stack

leetcode
九章

题目描述

Design a stack that supports push, pop, top, and retrieving the minimum
element in constant time.

  • push(x) – Push element x onto stack.
  • pop() – Removes the element on top of the stack.
  • top() – Get the top element.
  • getMin() – Retrieve the minimum element in the stack.

Example:

MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin();   --> Returns -3.
minStack.pop();
minStack.top();      --> Returns 0.
minStack.getMin();   --> Returns -2.

Tags: Stack, Design

Difficulty: Easy

答案



leetcode 150. Evaluate Reverse Polish Notation

难度:Middle

leetcode
九章

题目描述

Evaluate the value of an arithmetic expression in Reverse Polish
Notation
.

Valid operators are +, -, *, /. Each operand may be an integer or
another expression.

Note:

  • Division between two integers should truncate toward zero.
  • The given RPN expression is always valid. That means the expression would always evaluate to a result and there won’t be any divide by zero operation.

Example 1:

Input: ["2", "1", "+", "3", "*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9

Example 2:

Input: ["4", "13", "5", "/", "+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6

Example 3:

Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
Output: 22
Explanation: 
  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
= ((10 * (6 / (12 * -11))) + 17) + 5
= ((10 * (6 / -132)) + 17) + 5
= ((10 * 0) + 17) + 5
= (0 + 17) + 5
= 17 + 5
= 22

Tags: Stack

Difficulty: Medium

答案

leetcode 42. Trapping Rain Water

难度:Hard

leetcode
九章

题目描述

Given n non-negative integers representing an elevation map where the width
of each bar is 1, compute how much water it is able to trap after raining.


The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In
this case, 6 units of rain water (blue section) are being trapped. Thanks
Marcos
for contributing this image!

Example:

Input: [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6

Tags: Array, Two Pointers, Stack

Difficulty: Hard

答案

leetcode 341. Flatten Nested List Iterator

难度:Middle

leetcode
九章

题目描述

Given a nested list of integers, implement an iterator to flatten it.

Each element is either an integer, or a list – whose elements may also be
integers or other lists.

Example 1:

Input: [[1,1],2,[1,1]]
Output: [1,1,2,1,1]
Explanation: By calling _next_ repeatedly until _hasNext_ returns false, 
             the order of elements returned by _next_ should be: [1,1,2,1,1].

Example 2:

Input: [1,[4,[6]]]
Output: [1,4,6]
Explanation: By calling _next_ repeatedly until _hasNext_ returns false, 
             the order of elements returned by _next_ should be: [1,4,6].

Tags: Stack, Design

Difficulty: Medium

答案

leetcode 103. Binary Tree Zigzag Level Order Traversal

难度:Middle

leetcode
九章

题目描述

Given a binary tree, return the zigzag level order traversal of its nodes’
values. (ie, from left to right, then right to left for the next level and
alternate between).

For example:
Given binary tree [3,9,20,null,null,15,7],

  3
 / \
9  20
  /  \
 15   7

return its zigzag level order traversal as:

[
  [3],
  [20,9],
  [15,7]
]

Tags: Stack, Tree, Breadth-first Search

Difficulty: Medium

答案


:D 一言句子获取中...