代码随想录算法训练营第三十六天|435. 无重叠区间(undone)、763. 划分字母区间、56. 合并区间(undone)

该代码段展示了一个C#方法,用于找到给定字符串中每个连续出现的字母的最大索引范围,即字母区间,并将这些区间的长度存储在结果列表中。方法使用一个哈希表记录每个字母的最新出现位置,然后遍历字符串,更新右边界并添加新的区间长度。
摘要由CSDN通过智能技术生成

763. 划分字母区间

思路

public class Solution {
    public IList<int> PartitionLabels(string s) {
        IList<int> result = new List<int>();
        int[] hash = new int[26];
        for(int i = 0; i < s.Length;i++)
        {
            hash[s[i]-'a'] = i;
        }
        int left = 0;
        int right = 0;
        for(int i = 0;i < s.Length;i++)
        {
            right= right > hash[s[i]-'a'] ? right : hash[s[i]-'a'];
            if(i == right)
            {
                result.Add(right-left+1);
                left=i+1;
            }
        }
        return result;
    }
}
要添加一个统计展示组件 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、付费专栏及课程。

余额充值