forked from codepath/compsci_guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Check for Number
Jessica Sang edited this page Sep 14, 2024
·
1 revision
Unit 1 Session 2 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Will the list always contain only numbers?
- Yes.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop through a list of numbers and check each one to see if it matches the target num.
1) Loop through the input list
a) If the element matches the num, return true
2) Return the counter
def check_num(lst, num):
for item in lst:
if item == num:
return True
return False