zoukankan      html  css  js  c++  java
  • 腾讯面试编程题

    第1题:

    ####solution1##########case通过率为100%
    import copy
    input_l=input().strip()
    try:
        n=int(input_l)
        res = []
        for i in range(n):
            t = input()
            res.append(int(t))
        res2 = copy.deepcopy(res)
        minl = res[0]
        maxl = res[n - 1]
        j = 0
        temp = 0
        while j < n - 1:
            res.sort()
            a = res.pop()
            b = res.pop()
            res.append(a * b + 1)
            j = j + 1
        minl = res[0]
        k = 0
        while k < n - 1:
            res2.sort()
            a = res2.pop(0)
            b = res2.pop(0)
            res2.append(a * b + 1)
            k = k + 1
        maxl = res2[0]
        print(maxl - minl)
    except ValueError:
        print("输入的不是数字")
    

      

     解析:每次将列表中最大两个数进行指定运算后去除,将运算结果加入列表,这样得到最后一个数是最小数

                每次将列表中最小的两个数进行指定运算后去除,将运算结果加入列表,这样得到最后一个数是最大数

    第2题:

    第1题

    同 Leetcode的第2题

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
            cur=ListNode(0)
            head=cur
            temp=0
            a=0
            while l1 and l2:
                a=l1.val+l2.val+temp
                temp=0
                if a>=10:
                    temp=a//10
                    a=a%10
                node=ListNode(a)
                cur.next=node
                l1=l1.next
                l2=l2.next
                cur=cur.next
            while l2:
                a=l2.val+temp
                temp=0
                if a>=10:
                    temp=a//10
                    a=a%10
                node=ListNode(a)
                cur.next=node
                l2=l2.next
                cur=cur.next
            while l1:
                a=l1.val+temp
                temp=0
                if a>=10:
                    temp=a//10
                    a=a%10
                node=ListNode(a)     
                cur.next=node
                l1=l1.next
                cur=cur.next
            if temp:
                node=ListNode(temp)
                cur.next=node
                cur=cur.next
            return head.next
    

      

    第2题

  • 相关阅读:
    Office Access 2007 的连接方法变了
    程序员的灯下黑:坚持和良好心态近乎道
    Unity浅析
    WPF设置样式的几种方式
    关于常用 软件授权 Licence说明
    WCF消息队列
    委托利用GetInvocationList处理链式委托
    WCF chatroom源码解析
    写一个Jquery字体插件
    浅谈AsyncState与AsyncDelegate使用的异同
  • 原文地址:https://www.cnblogs.com/graybird/p/10752696.html
Copyright © 2011-2022 走看看