Easy-15

leetcode  448. Find All Numbers Disappeared in an Array          

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements of [1, n] inclusive that do not appear in this array.

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

Example:

Input:
[4,3,2,7,8,2,3,1]

Output:
[5,6]

AC:(用了额外空间)

/**
 * Return an array of size *returnSize.
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
    int* result=(int*)malloc(numsSize*sizeof(int));
    int* result_real=(int*)malloc((numsSize/2+1)*sizeof(int));
    int length=0;
    for(int i=0;i<numsSize;i++)
    {
        result[nums[i]-1]=1;
    }
    for(int i=0;i<numsSize;i++)
    {
        if(result[i]!=1)
        {
            result_real[length]=i+1;
            length++;
        }
    }
    *returnSize=length;
    return result_real;
}


AC:(改进)

/**
 * Return an array of size *returnSize.
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
    int* result=(int*)malloc(numsSize*sizeof(int));
    int length=0;
    for(int i=0;i<numsSize;i++)
    {
        int m=abs(nums[i])-1;
        if(nums[m]>0)
        {
            nums[m]=-nums[m];
        }
    }
    for(int i=0;i<numsSize;i++)
    {
        if(nums[i]>0)
        {
            result[length]=i+1;
            length++;
        }
    }
    *returnSize=length;
    return result;
}

### 修改 Vue-Easy-Tree 列表项间距的方法 在 Vue-Easy-Tree 组件中,如果需要调整 `list` 的间距样式,可以通过自定义 CSS 样式来实现。由于组件内部的样式通常是封装好的,因此直接修改其默认样式可能不会生效。以下是具体的解决方案: #### 方法一:全局覆盖样式 可以利用 Vue-Easy-Tree 提供的选择器或者类名,在项目的全局样式文件(如 `src/assets/styles/global.css` 或者 `App.vue` 的 `<style>` 部分)中添加自定义样式。 假设 Vue-Easy-Tree 使用了一个特定的类名为 `.vue-easy-tree-list-item` 来表示列表项,则可以在全局样式中这样写: ```css /* 调整列表项之间的垂直间距 */ .vue-easy-tree-list-item { margin-bottom: 10px; /* 设置底部外边距 */ } /* 如果需要调整水平间距 */ .vue-easy-tree-list-item { padding-left: 20px; /* 增加左侧内边距 */ } ``` 这种方法适用于希望在整个项目范围内统一应用该样式的场景[^1]。 --- #### 方法二:作用域样式 (Scoped Styles) 如果你只想在一个特定的组件中调整 Vue-Easy-Tree 的样式,而不想影响其他地方的使用,那么可以借助深选符 `/deep/` 或 `>>>` 来穿透作用域限制。 例如,在某个 Vue 单文件组件中的 `<style scoped>` 下编写如下代码: ```html <template> <div class="custom-vue-easy-tree"> <vue-easy-tree :data="treeData"></vue-easy-tree> </div> </template> <style scoped> .custom-vue-easy-tree /deep/ .vue-easy-tree-list-item { margin-bottom: 15px; padding-right: 10px; } </style> ``` 这里需要注意的是,不同版本的 Vue 可能对深选符的支持有所不同。Vue 3 推荐使用 `::v-deep` 替代 `/deep/` 和 `>>>`。 --- #### 方法三:动态绑定内联样式 如果间距值需要根据某些条件动态变化,可以直接通过 Vue 的 `:style` 属性绑定内联样式。例如: ```javascript <template> <vue-easy-tree :data="treeData" :style="{ marginBottom: listItemMargin }"></vue-easy-tree> </template> <script> export default { data() { return { listItemMargin: '20px', // 动态设置的外边距 }; }, }; </script> ``` 这种方式适合于需要基于逻辑计算或用户输入改变样式的场景。 --- #### 注意事项 当尝试修改第三方库的样式时,请务必查阅官方文档确认是否有内置 API 支持定制化需求。如果没有明确支持,通常推荐优先采用方法一或方法二,因为它们更加灵活且易于维护[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值