2562. 找出数组的串联值

题目

题解

  • 直接使用双指针,依次拼接
  • 如果指针结束指向同一个数,则再加上该数
java 复制代码
class Solution {
    public long findTheArrayConcVal(int[] nums) {

        int left = 0;
        int right = nums.length - 1;
        long res = 0;
        while (right > left) {
            int lv = nums[left];
            int rv = nums[right];
            while (rv > 0) {
                rv = rv / 10;
                lv = lv * 10;
            }
            res = res + lv + nums[right];

            left++;
            right--;
        }

        if (left == right) {
            return res + nums[left];
        }

        return res;

    }
}

本文由mdnice多平台发布

相关推荐
大模型教程1 天前
12天带你速通大模型基础应用(二)自动化调优Prompt
程序员·llm·agent
AI大模型1 天前
无所不能的Embedding(02) - 词向量三巨头之FastText详解
程序员·llm·agent
SimonKing1 天前
Apache Commons Math3 使用指南:强大的Java数学库
java·后端·程序员
AI大模型1 天前
无所不能的Embedding(03) - word2vec->Doc2vec[PV-DM/PV-DBOW]
程序员·llm·agent
袁煦丞1 天前
群晖NAS FTP远程文件仓库全球访问:cpolar内网穿透实验室第524个成功挑战
前端·程序员·远程工作
堆栈future2 天前
我的个人网站上线了,AI再一次让我站起来了
程序员·llm·aigc
大模型教程2 天前
AI Agent 发展趋势与架构演进
程序员·llm·agent
AI大模型2 天前
无所不能的Embedding(01) - 词向量三巨头之Word2vec模型详解&代码实现
程序员·llm·agent
程序员鱼皮2 天前
扒了下 Cursor 的提示词,被狠狠惊艳到了!
计算机·ai·程序员·大模型·互联网·编程