zoukankan      html  css  js  c++  java
  • 面试题



    1.写程序得到两个列表list的交集和差集

    2.写一个单例类

    3.用Python正则匹配HTML tag的时候,<.*>和<.*?>的区别
    第一种写法是,尽可能多的匹配,就是匹配到的字符串尽量长,第二中写法是尽可能少的匹配,就是匹配到的字符串尽量短。
    比如<tag>tag>tag>end,第一个会匹配<tag>tag>tag>,第二个会匹配<tag>,如果要匹配到二个 >,就只能自己写了
    http://www.cnblogs.com/Eva-J/articles/7228075.html#_label6

     


    4.下边代码会输出什么:

    def f(x,l=[]):
        for i in range(x):
            l.append(i*i)
    
        print (l)
    
    f(2)
    f(3,[3,2,1])
    f(3)

    5.平衡点:比如int[] numbers = {1,3,5,7,8,25,4,20}; 25前面的总和为24,25后面的总和也是24,25这个点就是平衡点;假如一个数组中的元素,其前面的部分等于后面的部分,那么这个点的位序就是平衡点

    要求:返回任何一个平衡点

     1 li = [1,3,5,7,8,25,4,20]  
     2 def main():  
     3     i = 0  
     4     length = len(li)  
     5     before = 0  
     6     after = 0  
     7     mark = 0  
     8     balance = 0  
     9     total = sum(li)  
    10     while True:  
    11         balance = i + 1  
    12         if balance + 1 > length -1:  
    13             return -1  
    14         if li[i] == li[balance+1]:  
    15             mark = balance  
    16             return (mark,li[mark])  
    17         else:  
    18             before = before + li[i]  
    19             other = total - before - li[balance]  
    20             if before == other:  
    21                 mark = balance  
    22                 return (mark,li[mark])  
    23         i += 1  
    24 if __name__ == "__main__":  
    25    print  main() 


  • 相关阅读:
    对于函数中多个返回值的处理
    Docker-compose 安裝单机版redis
    设计模式七大设计原则
    UML 设计技巧
    使用Docker 容器配置nexus3.29 私有仓库
    分布式消息Kafka通信原理分析
    分布式消息Kafka通信
    使用docker 搭建nexus3.29
    分布式消息Kafka初步认识及基本应用
    Dubbo 常用配置及源码分析
  • 原文地址:https://www.cnblogs.com/chongdongxiaoyu/p/9391437.html
Copyright © 2011-2022 走看看