Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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.