随手敲代码——删除数组重复元素(最高效版)

曾经面试的时候别人让手写出这段代码,当时写了一段,现在想来应该是写错了- -、,列出个我认为最高效的,引以为进鉴!

public static int[] removeReplicate(int[] a){
        int length = 0;
        boolean isExists = false;
        for(int i = 0;i <= a.length - 1;i++){
            for(int j = i + 1;j <= a.length - 1;j++){
                if(a[i] == a[j]){
                    isExists = true;
                    break;
                }
            }
            if(!isExists){
                a[length] = a[i];
                length++;
            }
            isExists = false;
        }
        int[] b = Arrays.copyOf(a, length);
        return b;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用媒体API的随手拍小程序代码的示例: ```html <!-- index.wxml --> <view class="container"> <camera bindtakephoto="takePhoto" /> <image src="{{photo}}" class="photo" /> </view> ``` ```javascript // index.js Page({ data: { photo: '' }, takePhoto: function (e) { const ctx = wx.createCameraContext(); ctx.takePhoto({ quality: 'high', success: (res) => { this.setData({ photo: res.tempImagePath }) } }) } }) ``` ```css /* index.wxss */ .container { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; } .photo { width: 300px; height: 300px; margin-top: 20px; border-radius: 50%; } ``` 这个小程序包含一个 `camera` 组件和一个 `image` 组件。当用户点击拍照按钮时,`takePhoto` 方法被调用。在 `takePhoto` 方法中,我们创建了一个 `camera` 上下文并调用了 `takePhoto` 方法。当照片拍摄成功后,我们将照片的临时路径设置为 `photo` 数据,这样就可以在 `image` 组件中显示照片了。 需要注意的是,使用摄像头 API 需要在 `app.json` 文件中声明相应的权限,例如: ```json { "permission": { "scope.userLocation": { "desc": "你的位置信息将用于小程序定位" }, "scope.camera": { "desc": "你的相机将用于拍摄照片" } } } ``` 此外,还需要在 `project.config.json` 文件中添加以下配置: ```json { "miniprogramRoot": "./", "appid": "你的小程序 AppID", "projectname": "随手拍小程序", "description": "一个使用媒体 API 的随手拍小程序", "setting": { "urlCheck": true, "es6": true, "postcss": true, "minified": true, "newFeature": true } } ``` 以上就是一个简单的使用媒体 API 的随手拍小程序代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值