当前位置:网站首页>[leetcode] small thinking of optimal division
[leetcode] small thinking of optimal division
2022-06-12 19:55:00 【PushyTao】

If there is only one number, you can directly return that number
If there are two numbers , The answer is “a/b”
If it is more than three numbers {
To maximize results , So let's make the divisor smaller . In the case of integers , Division only makes the number smaller and smaller , So put all the numbers except the first one in brackets , such as :
a/(b/c/d/…/f)
}
class Solution {
public:
string optimalDivision(vector<int>& nums) {
string ret = "";
int n = nums.size();
ret += to_string(nums[0]);
if(n == 1) return ret;
if (n > 1) ret += "/";
if (n > 2) ret += "(";
for(int i = 1;i <= n - 2;i ++) {
ret += to_string(nums[i]);
ret += "/";
}
ret += to_string(nums[n-1]);
if(n > 2) ret += ")";
return ret;
}
};
边栏推荐
- unity websockt一些知识:
- Negative remainder problem
- How to close icloud when Apple ID of Apple mobile phone forgets password and frequently jumps out to log in
- Index optimization principle
- 基于微信电子书阅读小程序毕业设计毕设作品(1)开发概要
- Are you confused about choosing a low code platform? Follow these three steps
- 94. 解析网页中的内容
- In 2022, 20 cities with the largest number of college students in China
- JDBC interface summary
- Detailed explanation of IO flow basic knowledge -- file and IO flow principle
猜你喜欢

基于微信电子书阅读小程序毕业设计毕设作品(5)任务书

Low code enables rural construction to open "smart mode"

unity websockt一些知识:

用户权限和组权限

Is it really hopeless to choose electronic engineering and be discouraged?

Experience Technology Department of ant group launched the 2023rd school recruitment

Microsoft Word tutorial, how to insert page numbers and table of contents in word?

Negative remainder problem

Demand and business model analysis -6- five topics

Demand and business model innovation - demand 4- overview of demand acquisition
随机推荐
Since using low code development, the development efficiency has been increased by 10 times
进程会计、进程时间、守护进程
unity websockt一些知识:
基于微信电子书阅读小程序毕业设计毕设作品(3)后台功能
System log
BigTable (II): how BigTable achieves scalability and high performance
Storage system overview
Macro definitions and functions
What is a hash index?
登录mysql
MySQL日志
Promise to solve hell function calls can be used infinitely
What does SQL replace or
Unsupported class file major version 60
Demand and business model analysis-3-design
Wechat e-book reading applet graduation design completion works (3) background function
Reading small programs based on wechat e-book graduation design works (7) Interim inspection report
Implementation of exec function and shell
Reading small program graduation design based on wechat e-book (5) assignment
【生成对抗网络学习 其三】BiGAN论文阅读笔记及其原理理解