problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::different_ways_to_add_parentheses::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< int > diffWaysToCompute (const string &expression)
 
static vector< int > eval (const string &expr, int start, int end)
 

详细描述

在文件 leetcode.h3006 行定义.

成员函数说明

◆ diffWaysToCompute()

vector< int > leetcode::different_ways_to_add_parentheses::Solution::diffWaysToCompute ( const string &  expression)
static

在文件 leetcode.cpp8488 行定义.

8488 {
8489 vector ans = eval(expression, 0, expression.length() - 1);
8490 sort(ans.begin(), ans.end());
8491 return ans;
8492 }
static vector< int > eval(const string &expr, int start, int end)
Definition: leetcode.cpp:8452

引用了 eval().

被这些函数引用 leetcode::different_ways_to_add_parentheses::TEST().

◆ eval()

vector< int > leetcode::different_ways_to_add_parentheses::Solution::eval ( const string &  expr,
int  start,
int  end 
)
static

在文件 leetcode.cpp8452 行定义.

8452 {
8453 vector<int> ans;
8454 bool allDigit = true;
8455 for(int i = start; i <= end; i++) {
8456 if(!isdigit(expr[i])) {
8457 allDigit = false;
8458 vector left = eval(expr, start, i - 1);
8459 vector right = eval(expr, i + 1, end);
8460 for(const auto &l: left) {
8461 for(const auto &r: right) {
8462 switch(expr[i]) {
8463 case '+':
8464 ans.emplace_back(l + r);
8465 break;
8466 case '-':
8467 ans.emplace_back(l - r);
8468 break;
8469 case '*':
8470 ans.emplace_back(l * r);
8471 break;
8472 }
8473 }
8474 }
8475 }
8476 }
8477 if(allDigit) {
8478 int val = 0;
8479 for(int i = start; i <= end; i++) {
8480 val *= 10;
8481 val += expr[i] - '0';
8482 }
8483 ans.emplace_back(val);
8484 }
8485 return ans;
8486 }

引用了 eval(), acwing::acwing1929::left , 以及 acwing::acwing1929::right.

被这些函数引用 diffWaysToCompute() , 以及 eval().


该类的文档由以下文件生成: