[2021秋招笔试记录]远景智能_9.10_算法工程师

编程题一

n阶乘的结果的末尾有几个零
eg:3!=6 output:0
5!= 120 output:1

def NumberOfZero(n):
    if n == 1:
        res = 1
    res = 1
    for i in range(1,n+1):
        res *= i
    s = str(res)
    count = 0
    for num in s[::-1]:
        if num == '0':
            count += 1
        else:
            break
    return count

编程题二:

“” {} () [] 闭合,输出true;否则输出false
eg:
“I’m happy” true
I’m [ happy. false
“()” true

def ClosedString(s):
    stack = []
    for letter in s:
        print(stack)
        if letter in '([{' or (letter == '"' and '"' not in stack):
            stack.append(letter)
        elif letter == ']':
            if stack.pop() != '[':
                return 'false'
        elif letter == ')':
            if stack.pop() != '(':
                return 'false'
        elif letter == '}':
            if stack.pop() != '{':
                return 'false' 
        elif letter == '"':
            if stack.pop() != '"':
                return 'false'
    if len(stack) == 0:
        return 'true'
    else:
        return 'false'

你可能感兴趣的:([2021秋招笔试记录]远景智能_9.10_算法工程师)