classSolution: defminOperations(self, logs: List[str]) -> int: cur = 0 for log in logs: if log == '../': if cur: cur -= 1 elif log == './': continue else: cur += 1 return cur
classSolution: defminOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int: ans = 0 res = 0 p = 0 w = 0 i = 0 for c in customers: i += 1 w += c b = min(w, 4) w -= b p += b * boardingCost - runningCost if p > res: res = p ans = i while w: i += 1 b = min(w, 4) w -= b p += b * boardingCost - runningCost if p > res: res = p ans = i return ans if ans else-1
defgetInheritanceOrder(self) -> List[str]: res = [] stack = [self.root] while stack: node = stack.pop() ifnot node.is_death: res.append(node.name) for child in reversed(node.children): stack.append(child) return res
classSolution { int tot[25]; public: intmaximumRequests(int n, vector<vector<int>> &req){ int ans = 0; int m = req.size(); int lim = (1 << m) - 1; for (int i = 1; i <= lim; ++i) { for (int j = 0; j < n; ++j) tot[j] = 0; int cnt = 0; for (int j = 0, k = 1; j < m; ++j, k <<= 1) if (i & k) { ++tot[req[j][1]], --tot[req[j][0]]; ++cnt; } bool flag = true; for (int j = 0; j < n; ++j) { if (tot[j] != 0) { flag = false; break; } } if (flag) ans = max(ans, cnt); } return ans; } };