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

#include <leetcode.h>

静态 Public 成员函数

static int get_cost (int startAt, int moveCost, int pushCost, const int num[4])
 
static int minCostSetTime (int startAt, int moveCost, int pushCost, int targetSeconds)
 

详细描述

在文件 leetcode.h923 行定义.

成员函数说明

◆ get_cost()

int leetcode::minimum_cost_to_set_cooking_time::Solution::get_cost ( int  startAt,
int  moveCost,
int  pushCost,
const int  num[4] 
)
static

在文件 leetcode.cpp2307 行定义.

2307 {
2308 int cost = 0;
2309 int current = startAt;
2310 bool flag = true;
2311 for(int i = 0; i < 4; i++) {
2312 if(num[i] == 0 && flag) {
2313 continue;
2314 }
2315 flag = false;
2316 if(num[i] != current) {
2317 cost += moveCost;
2318 current = num[i];
2319 }
2320 cost += pushCost;
2321 }
2322 return cost;
2323 }

被这些函数引用 minCostSetTime().

◆ minCostSetTime()

int leetcode::minimum_cost_to_set_cooking_time::Solution::minCostSetTime ( int  startAt,
int  moveCost,
int  pushCost,
int  targetSeconds 
)
static

在文件 leetcode.cpp2288 行定义.

2288 {
2289 int ans = (moveCost + pushCost) * 4;
2290 int minute = targetSeconds / 60;
2291 int second = targetSeconds % 60;
2292 while(minute > 99) {
2293 minute -= 1;
2294 second += 60;
2295 }
2296 const int num[4] = {minute / 10, minute % 10, second / 10, second % 10};
2297 ans = min(ans, get_cost(startAt, moveCost, pushCost, num));
2298 if(second + 60 < 100 && minute - 1 >= 0) {
2299 second += 60;
2300 minute -= 1;
2301 const int num[4] = {minute / 10, minute % 10, second / 10, second % 10};
2302 ans = min(ans, get_cost(startAt, moveCost, pushCost, num));
2303 }
2304 return ans;
2305 }
static int get_cost(int startAt, int moveCost, int pushCost, const int num[4])
Definition: leetcode.cpp:2307

引用了 get_cost().


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