小编pay*_*npy的帖子

大量模式的数据结构

在一次采访中,我被要求提出可以容纳数百万个模式的数据结构,并通过它们快速搜索以找到最长的匹配模式.

例如,模式如下:

1- 8876 8893 87          | true
2- 8876 889              | false
3- 8876 8                | false
4- 887                   | true
Run Code Online (Sandbox Code Playgroud)

输入是一个至少有2位且最多18位的数字,我们需要从数据结构中找到最长的匹配模式,并在结尾处提取布尔值.

例如,8876 8893 9943 53将匹配1true返回.8876 8397 5430 74将匹配3false返回.

我的回答是使用一棵树并key value在每个级别都有一个对列表.作为数字和值的键是null或等于boolean,具体取决于它是否是模式的结尾.喜欢:

# matching 8875
# start the search by first digit
[..., (7, null), (8, null), (9, null)] 
                  ^
                 [..., (7, null), (8, null), (9, null)] 
                                   ^
                                   [..., (7, true), (8, null), ...]
# at …
Run Code Online (Sandbox Code Playgroud)

algorithm pattern-matching data-structures

5
推荐指数
1
解决办法
415
查看次数

Angular嵌套指令仅渲染第一个子节点

我有一个parent指令,其中包括两个子指令,firstsecond.我注意到只有第一个孩子被渲染.另外,如果我在第一个之前放置了一些任意的HTML标记,那么它都会被渲染,但是如果我把它们放在那之后那么它们就不会出现了.为什么是这样?

看到jsfiddle:

<!-- index.html -->
<div ng-app="myApp">
  <my-parent-dir />
</div>

<!-- main.js -->
var app = angular.module("myApp", []);
app.directive("myParentDir", function() {
    return {
        restrict: 'E',
        template: '<my-first-child /> <my-second-child />'
    };
});

app.directive("myFirstChild", function() {
    return {
        restrict: 'E',
        template: '<input type="text" placeholder="first">',
    };
});

app.directive("mySecondChild", function() {
    return {
        restrict: 'E',
        template: '<input type="text" placeholder="second">',
    };
});
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

2
推荐指数
1
解决办法
239
查看次数