0
Please help me
Hey everyone, I've been learning python for over a year and the amount of things I've managed to learn aren't so many. I've learnt the basics and so many concepts but when I go to leetcode and I try to apply my knowledge, I just can't seem to figure it out, even for easy problems like Two Sum. Sometimes I even wonder if I'm the problem. Please assist me.
2 Respostas
+ 1
Kuri
#The basics of most codes is defining what you want to do
def add(a,b): # the function
return a+b # simplistic algorithm
a = int(input()) # no. 1
b = int(input()) # no. 2
print(add(a,b)) # call function
Math wording and interpretation sometimes can be confusing ..
Leetcode Task:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
nums = [2,7,11,15]
a= int(input()) # no. 1
b= int(input()) # no. 2
# if target is 9 a = 0 and b = 1
print(nums[a] + nums[b])
0
Kuri here are two examples in this code...
https://sololearn.com/compiler-playground/cjKwlEx6zJTR/?ref=app



