代码随想录算法训练营第三十五天|860. 柠檬水找零、406.根据身高重建队列(undone)、 452. 用最少数量的箭引爆气球

860. 柠檬水找零

public class Solution {
    public bool LemonadeChange(int[] bills) {
        Dictionary<int, int> dict = new Dictionary<int, int>() {
            {5,0},
            {10,0}
        };
        int count = 0;
        for(int i = 0;i < bills.Length;i++)
        {
            if(bills[i] == 5) dict[5]++;
            if(bills[i] == 10) 
            {
                dict[10]++;
                if(dict[5] > 0) dict[5]--;
                else return false;
            }
            if(bills[i] == 20) 
            {
                if(dict[10]> 0 && dict[5] > 0)
                {
                    dict[10]--;
                    dict[5]--;
                } else if(dict[5] >= 3)
                {
                    dict[5]-=3;
                }
                else return false;
            }
        }
        return true;
    }
}

452. 用最少数量的箭引爆气球

思路

public class Solution {
    public static int CompareStrings(int[] a, int[] b)
    {
        return a[0] < b[0] ? -1 : 1;
    }
    public int FindMinArrowShots(int[][] points) {
        int sum = 1;
        Array.Sort(points, CompareStrings);
        for (int i = 1; i < points.Length; i++)
        {
            if (points[i][0] > points[i - 1][1]) sum++;
            else {  
                points[i][1] = points[i - 1][1] < points[i][1] ?  points[i - 1][1] : points[i][1]; // 更新重叠气球最小右边界
            }
        }
        return sum;
    }
}
要添加一个统计展示组件 Footer.vue,可以按照以下步骤进行操作: 1. 在 src/components 目录下创建一个名为 Footer.vue 的文件,编写统计展示组件的模板和样式,例如: ```html <template> <div class="footer"> <span>已完成 {{ doneCount }} 项</span> <span>未完成 {{ undoneCount }} 项</span> </div> </template> <style> .footer { display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f0f0f0; } </style> ``` 2. 在 App.vue 中导入 Footer 组件,并在模板中使用它,例如: ```html <template> <div> <h1>Todo List</h1> <input v-model="inputValue" @keyup.enter="handleAddItem"/> <ul> <li v-for="(item, index) in todoList" :key="index"> <span :class="{ 'done': item.done }" @click="handleToggleDone(index)">{{ item.content }}</span> <button @click="handleDeleteItem(index)">删除</button> </li> </ul> <footer-component :done-count="doneCount" :undone-count="undoneCount"></footer-component> </div> </template> <script> import Footer from './components/Footer.vue' export default { components: { 'footer-component': Footer }, data() { return { todoList: [ { content: '学习 Vue.js', done: true }, { content: '学习 React', done: false }, { content: '学习 Angular', done: false } ], inputValue: '' } }, computed: { doneCount() { return this.todoList.filter(item => item.done).length }, undoneCount() { return this.todoList.filter(item => !item.done).length } }, methods: { handleAddItem() { if (this.inputValue.trim() === '') return this.todoList.push({ content: this.inputValue, done: false }) this.inputValue = '' }, handleToggleDone(index) { this.todoList[index].done = !this.todoList[index].done }, handleDeleteItem(index) { this.todoList.splice(index, 1) } } } </script> ``` 3. 在 Footer.vue 中定义 props 接收父组件传递的数据,例如: ```js export default { props: { doneCount: { type: Number, required: true }, undoneCount: { type: Number, required: true } } } ``` 4. 在 Footer.vue 中使用 props 中接收的数据,例如: ```html <template> <div class="footer"> <span>已完成 {{ doneCount }} 项</span> <span>未完成 {{ undoneCount }} 项</span> </div> </template> ``` 这样就完成了添加统计展示组件 Footer.vue 的操作。在 App.vue 中使用 footer-component 标签即可展示 Footer.vue 组件的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值