思路:将A中每次从后往前取的数,加到K上面(K最大为10000,不存在越界问题),然后每次取K的最后一位数(借助取余),计算完后将K除以10,直到K等于0。 publicList<Integer>addToArrayForm2(int[] A,intK){ List<Integer> result =newArrayList<Integer>();inti=A.length-1, tem = K;while(i >=0|| tem >...
leetcode 989. 数组形式的整数加法(Add to Array-Form of Integer) 目录 题目描述: 示例1: 示例2: 示例3: 示例4: 解法: 题目描述: 对于非负整数 X 而言,X 的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果 X = 1231,那么其数组形式为 [1,2,3,1]。 给定非负整数 X 的数组形式 A,返回...
For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1]. Given the array-form A of a non-negative integer X, return the array-form of the integer X+K. Example 1: In...
vector<int> addToArrayForm(vector<int> &A, int K) { int len = A.size(); if (K == 0) return A; int flag = 0; //进位 int index = len - 1; vector<int> res; // 逐位相加,flag存储进位 while (K > 0 || index >= 0) { int a = 0, b = 0; if (K >= 0) a = ...
简介:Leetcode-Easy 989. Add to Array-Form of Integer 题目描述 对于非负整数X,X的数组形式是从左到右顺序的数字数组。例如,如果X = 1231,则数组形式为[1,2,3,1]。 给定非负整数X的数组形式A,返回整数X + K的数组形式。 Example 1: Input: A = [1,2,0,0], K = 34Output: [1,2,3,4]Ex...
236 lowest-common-ancestor-of-a-binary-tree 📝 Medium 237 delete-node-in-a-linked-list 📝 Easy 238 product-of-array-except-self 📝 Medium 239 sliding-window-maximum 📝 Hard 240 search-a-2d-matrix-ii 📝 Medium 241 different-ways-to-add-parentheses Medium 242 valid-anagram 📝 Easy...
989 Add to Array-Form of Integer Easy Solution 990 Satisfiability of Equality Equations Medium Solution 991 Broken Calculator Medium Solution 992 Subarrays with K Different Integers Hard Solution 993 Cousins in Binary Tree Easy Solution 994 Rotting Oranges Medium Solution 995 Minimum Number of K Conse...
0989 Add to Array-Form of Integer 44.2% Easy 0990 Satisfiability of Equality Equations Go 44.9% Medium 0991 Broken Calculator 45.5% Medium 0992 Subarrays with K Different Integers Go 48.6% Hard 0993 Cousins in Binary Tree Go 52.0% Easy 0994 Rotting Oranges 47.8% Medium 0995 Minimum ...
The problem "Two Sum" requires finding two numbers in aninteger arraysuch that their sum equals a specifiedtargetnumber. You need to returnthe indices ofthese two numbers, whereindices start from 0. The indices ofthe two numbers cannot be the same, and there isexactly one solutionfor each ...
【题目】Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by updating the element at index i to val. Example: 代码语言:javascript 复制 Given nums = [1, 3...