摘要: Sublime Text 4 破解笔记 偶然看到Sublime已经更新到版本4了,多了许多很nice的新特性,例如: 船新 UI 感知上下文的自动补全 支持 TypeScript, JSX 和 TSX GPU 渲染 ... 不得不说sublime是轻量化IDE性能王者,比vscode要快不少,不过v 阅读全文
posted @ 2021-06-25 18:38 益达的博客 阅读(32401) 评论(78) 推荐(55) 编辑

2022年1月17日

用例:在递增数组arr中寻找大于等于target的最小元素索引

思路:利用双指针,采用二分法查找左边界

代码:

    public static int left_bound(int[] arr, int target){
        if (arr.length == 0) return -1;
        int left = 0;
        int right = arr.length - 1;
        while(left<right){
            int mid = left + (right - left ) / 2;
            if(arr[mid] == target ){
                right = mid;
            }else if (arr[mid] < target){
                left ++;
            }else if (arr[mid] > target){
                right = mid;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,2,4,6,7,8,8,8,8,9,10,16,19};
        int index = left_bound(arr, 8);
        System.out.println(index);
     //输出 5 }

 解读:

当目标元素target不存在数组arr中时,搜索左侧边界的二分搜索的返回值可以做以下几种解读

1、返回的这个值是arr中大于等于target的最小元素索引。

2、返回的这个值是target应该插入在arr中的索引位置。

3、返回的这个值是arr中小于target的元素个数。

比如在有序数组arr= [2,3,5,7]中搜索target = 4,搜索左边界的二分算法会返回 2,你带入上面的说法,都是对的。

所以以上三种解读都是等价的,可以根据具体题目场景灵活运用

posted @ 2022-01-17 11:07 益达的博客 阅读(104) 评论(0) 推荐(0) 编辑

2021年5月12日

摘要: python三元表达式(三目运算符)的坑 通过网上学习,知道python三元运算有两种写法 value = true_value if condition else false_value value = condition and true_value or false_value 第二种写法利用 阅读全文
posted @ 2021-05-12 15:48 益达的博客 阅读(1025) 评论(0) 推荐(0) 编辑

2019年12月27日

摘要: 以Java为例: 饿汉: public final class VirtualCore { private static VirtualCore gCore = new VirtualCore(); private VirtualCore() { } public static VirtualCor 阅读全文
posted @ 2019-12-27 10:51 益达的博客 阅读(1084) 评论(0) 推荐(0) 编辑

2017年4月27日

摘要: 阅读文章后用一个流程图来总结__index的规则用法 总结一下Lua查找一个表元素时的规则,其实就是如下3个步骤:1.在表中查找,如果找到,返回该元素,找不到则继续2.判断该表是否有元表,如果没有元表,返回nil,有元表则继续3.判断元表(操作指南)中有没有关于索引失败的指南(即__index方法) 阅读全文
posted @ 2017-04-27 14:52 益达的博客 阅读(1550) 评论(0) 推荐(0) 编辑

2017年4月26日

摘要: 阅读了文章后用流程图来总结一下 __newindex的规则: a.如果__newindex是一个函数,则在给table不存在的字段赋值时,会调用这个函数。b.如果__newindex是一个table,则在给table不存在的字段赋值时,会直接给__newindex的table赋值。 应用: 1.__ 阅读全文
posted @ 2017-04-26 18:08 益达的博客 阅读(1797) 评论(0) 推荐(0) 编辑
摘要: 墙裂推荐!支持众多语言,方便学习,测试,地址如下 https://www.tutorialspoint.com/codingground.htm 阅读全文
posted @ 2017-04-26 15:44 益达的博客 阅读(362) 评论(0) 推荐(0) 编辑
摘要: 先看一段代码: 测试: 1: 输出 function: 0x7f0d0884ae00 test in onTouch 2: print(handler(c,c.onTouch)) print((function()c.onTouch(c)end)) 输出 function: 0x7f44d8d2ab 阅读全文
posted @ 2017-04-26 15:34 益达的博客 阅读(939) 评论(0) 推荐(0) 编辑

2015年7月17日

摘要: 实现类似翻扑克牌的效果代码如下: OrbitCamera* rotate1; OrbitCamera* rotate2; if(towardRight){//向右翻转 rotate1=OrbitCamera::create(0.4f,1,... 阅读全文
posted @ 2015-07-17 16:33 益达的博客 阅读(368) 评论(0) 推荐(0) 编辑

2015年6月18日

摘要: 写了一个方法,在onCreate和onResume中调用即可,4.4以上可用。private void openImmersiveMode() { if (android.os.Build.VERSION.SDK_INT > 18) { Window window... 阅读全文
posted @ 2015-06-18 14:24 益达的博客 阅读(278) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示