Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
AhkunTa
Arithmetic
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Arithmetic
/
LeetCode
/
860_javascript.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
74 lines (57 loc) · 2.05 KB
master
Breadcrumbs
Arithmetic
/
LeetCode
/
860_javascript.js
Copy path
Top
File metadata and controls
Code
Blame
74 lines (57 loc) · 2.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 在柠檬水摊上,每一杯柠檬水的售价为 5 美元。
// 顾客排队购买你的产品,(按账单 bills 支付的顺序)一次购买一杯。
// 每位顾客只买一杯柠檬水,然后向你付 5 美元、10 美元或 20 美元。你必须给每个顾客正确找零,也就是说净交易是每位顾客向你支付 5 美元。
// 注意,一开始你手头没有任何零钱。
// 如果你能给每位顾客正确找零,返回 true ,否则返回 false 。
// 示例 1:
// 输入:[5,5,5,10,20]
// 输出:true
// 解释:
// 前 3 位顾客那里,我们按顺序收取 3 张 5 美元的钞票。
// 第 4 位顾客那里,我们收取一张 10 美元的钞票,并返还 5 美元。
// 第 5 位顾客那里,我们找还一张 10 美元的钞票和一张 5 美元的钞票。
// 由于所有客户都得到了正确的找零,所以我们输出 true。
// 示例 2:
// 输入:[5,5,10]
// 输出:true
// 示例 3:
// 输入:[10,10]
// 输出:false
// 示例 4:
// 输入:[5,5,10,10,20]
// 输出:false
// 解释:
// 前 2 位顾客那里,我们按顺序收取 2 张 5 美元的钞票。
// 对于接下来的 2 位顾客,我们收取一张 10 美元的钞票,然后返还 5 美元。
// 对于最后一位顾客,我们无法退回 15 美元,因为我们现在只有两张 10 美元的钞票。
// 由于不是每位顾客都得到了正确的找零,所以答案是 false。
// 提示:
// 0 <= bills.length <= 10000
// bills[i] 不是 5 就是 10 或是 20
/**
* @param {number[]} bills
* @return {boolean}
*/
// 贪心最先减去10块
var lemonadeChange = function(bills) {
let five = 0,ten = 0;
for(let i=0; i<bills.length; i++){
if(bills[i] == 5){
five ++;
}else if(bills[i] == 10){
ten ++;
five --;
}else {
if(ten>0){
ten --;
five --
}else {
five -=3;
}
}
if(five < 0){
return false;
}
}
return true;
};
You can’t perform that action at this time.