Skip to main content
 首页 » 编程设计

python之我知道这很原始,但我想让这个功能以更有效的方式在更短的时间内工作

2025年05月04日9www_RR

instructions = Given an int array length 2, return True if it contains a 2 or a 3.

  def has23(nums): 
    if nums[0] == 2 or nums[0]== 3 : 
      return True  
    elif nums[1] == 2 or nums[1]==3 : 
      return True  
    else: 
      return False 

请您参考如下方法:

试试这个:

def has23(nums): 
    return 2 in nums or 3 in nums