| const code = `def twoSum(nums, target): |
| lookup = {} |
| for i, num in enumerate(nums): |
| complement = target - num |
| if complement in lookup: |
| return [lookup[complement], i] |
| lookup[num] = i |
| |
| nums = list(map(int, input('Enter numbers: ').split())) |
| target = int(input('Enter target: ')) |
| |
| result = twoSum(nums, target) |
| print('Result:', result)`; |
|
|
| fetch('http://localhost:5000/api/compile', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ code: code, language: 'python', input: '2 7 11 15\n9' }) |
| }).then(res => res.json()).then(console.log).catch(console.error); |
|
|