ChatASD
const twoSum = function (nums, target) { let target2 = [] for (let i = 0; i < nums.length; i++) { for (let j = 0; j < nums.length; j++) { if (nums[i] + nums[j] === target) { target2.push(i, j) } } } return target2 } nums = [2, 7, 11, 15] target = 9 console.log(twoSum(nums, target)) qayerda xatolik bor tushuntir sodda qilib
agar [3,2,4] kiritilsachi va target 6 bo'lsa 1, 2 qaytadimi
lekin 0, 0 qaytayaptiku
const addTwoNumbers = function (l1, l2) { l1.reverse() l2.reverse() const l11 = Number(l1.join('')) const l22 = Number(l2.join('')) const newRes = String(l11 + l22) const myArray = [] for (let i = 0; i < newRes.length; i++) { myArray.push(Number(newRes[i])) } myArray.reverse() return myArray } const l1 = [2, 4, 3] const l2 = [5, 6, 4] console.log(addTwoNumbers(l1, l2)) qayerda xato tushuntir
Line 2 in solution.js l1.reverse() ^ TypeError: l1.reverse is not a function Line 2: Char 5 in solution.js (addTwoNumbers) Line 27: Char 19 in solution.js (Object.<anonymous>) Line 16: Char 8 in runner.js (Object.runner) Line 14: Char 26 in solution.js (Object.<anonymous>) at Module._compile (node:internal/modules/cjs/loader:1554:14) at Object..js (node:internal/modules/cjs/loader:1706:10) at Module.load (node:internal/modules/cjs/loader:1289:32) at Function._load (node:internal/modules/cjs/loader:1108:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:220:24) Node.js v22.14.0. shu xatolik berayapti
Given a string s, find the length of the longest substring without duplicate characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Note that "bca" and "cab" are also correct answers. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring. Constraints: 0 <= s.length <= 5 * 104 s consists of English letters, digits, symbols and spaces. tushuntir lekin ishlab berma va tarjimasini qilib ber