LeetCode 刷题笔录 Add Two Numbers

【数字孪生与仿真技术】14:数据驱动+机理模型:工业级混合建模实战(附MATLAB完整代码+案例解析) 摘要 本文针对工业建模中机理模型精度不足和数据驱动模型缺乏物理约束的痛点,提出混合建模技术作为解决方案。文章系统阐述了混合建模的3种主流架构(参数校正型、残差补偿型、组件替换型),结合清华大学催化裂化装置的实际案例,分析混合建模的工业应用价值。同时以连续搅拌反应釜(CSTR)为例,提供MATLAB环境下残差补偿型混合模型的完整实现代码,详细展示从机理模型构建到数据驱动补偿的全流程,并给出工程实践中的应对策略,为工业建模提供可落地的技术方案。 关键词 混合建模、机理模型、数据驱动、工业建模、MATLAB 阅读详情

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8


这题看起来没啥好说的,挨个顺序扫描就行了。要注意null的位置以及进位的问题。我的代码通不过测试。。。输入{9},{9}显示我的程序返回是{9},{1},而答案应该是{8},{1}。但是我把这代码在自己机器上用eclipse编译完了答案是正确的。。。也看不出自己哪里有错,可能是leetcode编译的问题吧。先记下来再说。

private boolean carry = false;      //set the flag to true if a carry is needed 
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        // Start typing your Java solution below
        // DO NOT write main() function
        int first = add(l1.val, l2.val);
        ListNode previous = new ListNode(first);      //the first node of the answer linked list
        ListNode header = previous;
        for(l1 = l1.next, l2 = l2.next; l1 != null && l2 != null; l1 = l1.next, l2 = l2.next){
            previous = previous.next = new ListNode(add(l1.val, l2.val));
        }
        if(l1 == null && l2 == null){
            if(carry){
                previous = previous.next = new ListNode(1);
            }
        }
        else if(l1 == null){
            while(l2 != null){
                previous = previous.next = new ListNode(l2.val);
                l2 = l2.next;
            }
        }
        else if(l2 == null){
            while(l1 != null){
                previous = previous.next = new ListNode(l1.val);
                l1 = l1.next;
            }
        }
        
        return header;
    }
    /**
     * add the two numbers
     * return the last digit of the result of the sum of the two numbers
     * if the sum is larger than 10, set the carry flag to true
     */
    private int add(int a, int b){
        int result = a + b;
        if(carry){
            result++;
        }
        if(result < 10){
            carry = false;
            return result;
        }
        else{
            result = result % 10;
            carry = true;
            return result;
        }
    }


【华为OD技术面试手撕真题】25、验证IP地址 | 手撕真题+思路参考+代码解析(C & C++ & Java & Python & JS) 验证IP地址 华为od机试真题,华为OD技术二面,华为od机考,华为od手撕真题,华为od技术二面,华为od机试,华为OD机试的高频手撕代码题,华为od八股文 阅读详情

相关推荐

PyTorch实战:从零构建CNN图像分类模型

卷积神经网络(CNN)作为计算机视觉的核心架构,通过局部连接和权值共享机制高效处理图像数据。其核心组件包括卷积层、池化层和全连接层,其中PyTorch的动态计算图特性为CNN实现提供了灵活的开发环境。在工程实践中,使用CIFAR-10这类标准数据集可以快速验证模型性能,而数据增强和批归一化等技术能有效提升模型泛化能力。通过PyTorch实现CNN不仅能够掌握图像分类的基本原理,还能为后续迁移学习和复杂视觉任务打下基础,特别是在结合Adam优化器和学习率调度策略后,模型收敛速度和准确率都能得到显著提升。

weixin_42405592的博客 318

LeetCode刷题笔录 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

likecool21的专栏 1万+

Unity PSD分层导入插件ps2d原理与实战指南

PSD作为UI设计主流源文件,其图层结构、混合模式、文字矢量属性等核心语义在传统引擎导入中普遍丢失,导致设计还原度低、多语言适配难、运行时不可控。ps2d通过深度解析PSD二进制规范,将图层映射为GameObject树、文字转为TextMeshPro可编辑组件、形状生成矢量Mesh、蒙版与图层样式编译为定制Shader,实现设计意图的精准程序化表达。该方案显著提升UI开发效率,支撑高保真还原、动态修改、分辨率自适应及运行时热重载等工程需求,是Unity中连接设计师与程序员的关键工作流中枢。

weixin_32943857的博客 348

LeetCode刷题笔录 Two Sum

Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the

likecool21的专栏 1万+

风光储互补微电网在偏远地区的应用实践:从建模到仿真全解析

本文深入解析了风光储互补微电网在偏远地区的应用实践,从系统设计到仿真建模全流程。通过Simulink等工具进行动态仿真,验证了系统在多种工况下的可靠性,并结合实际案例展示了其显著的经济和环保效益。文章为从业者提供了从技术路径到实施优化的全面指导。

weixin_29047545的博客 269

vCenter6.7证书过期导致503报错的全面修复指南:从STS证书更新到SSL信任修复

本文详细解析了VMware vCenter 6.7因STS证书过期导致503服务不可用错误的根本原因,并提供了从诊断、更新STS证书到修复SSL信任链的完整解决方案。通过命令行工具检查证书状态,使用官方脚本更新过期STS证书,并利用lsdoctor工具修复深层SSL信任问题,最终指导用户使用certificate-manager彻底重置所有证书,帮助管理员快速恢复vCenter服务。

pz890123的博客 1293

LeetCode刷题笔录 Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.Th

likecool21的专栏 6928

行业变革下的功能安全落地痛点3:高阶智驾安全责任转移 —— 从 “人为中心” 到 “机器主责” 的产业阵痛

文章围绕高阶智驾(L3 级)落地挑战,探讨安全责任从 “人控” 向 “机控” 转移的本质、技术短板导致的责任模糊、全球法规实践及技术 - 法规 - 保险的破局路径。

my9111526 126

Stanford Algorithms学习:Clustering 2

这是紧接上面的一道题,比较有趣 Question 2 In this question your task is again to run the clustering algorithm from lecture, but on a MUCH bigger graph. So big, in fact, that the distances (i.e., edge costs

likecool21的专栏 2567

AFSim2.9.0学习笔记 —— 1、AFSim及完整工具介绍(文末附:完整afsim2.9.0源码、编译好的完整工具包、中文教材等)

AFSim2.9.0学习笔记 —— 1、AFSim及完整工具介绍(附:完整afsim2.9.0源码、编译好的完整工具包、中文教材等)

5172

Qt 调用YOLO模型(代码)

本文介绍了如何在 Qt C++ 环境中集成 YOLO 模型进行目标检测,包括模型封装、界面设计和实时处理等关键步骤。通过这种方法,你可以快速开发出具有目标检测功能的 Qt 应用程序,应用于监控系统、机器人视觉、图像分析等多个领域。

轩宇的博客 259

Stanford Algorithms学习:Clustering

第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。 Question 1 In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a

likecool21的专栏 2507

LeetCode刷题笔录Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:

likecool21的专栏 1296

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

LeetCode刷题笔录Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

likecool21的专栏 1109

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

LeetCode刷题笔录 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 这题比较简单

likecool21的专栏 1043

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

LeetCode刷题笔录Unique Binary Search Trees

这里有个讲解(印度人口音真难懂)

likecool21的专栏 1043

LeetCode刷题笔录Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

likecool21的专栏 1001

LeetCode刷题笔录 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 随手写的一个,正常的读出每一位的数字然后反序: import java.lang.Math; public class Solution { public int revers

likecool21的专栏 941

LeetCode刷题笔录Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the tota

likecool21的专栏 878

LeetCode刷题笔录Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

likecool21的专栏 865

LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这题可以kan'chu'lai

likecool21的专栏 855

Spring AI + GPT-5.5 + Ollama 配置教程:Base URL、超时与流式调用

由于不同 Spring AI、Spring Boot 小版本之间仍可能存在差异,创建项目时应检查 Spring Initializr、Spring AI BOM 和官方兼容矩阵,不要直接复制旧教程中的 Starter 名称和版本号。多人项目最好隔离不同客户端,并在脱敏前提下记录最终 URL、状态码、请求耗时、请求 ID 和模型 ID。Spring AI 接入模型 API,至少要同时确认 Starter、Base URL、请求路径、API Key、模型 ID、连接超时、读取超时和流式客户端这 8 项。

2601_95893075的博客 224

【JVM】对象内存布局

HotSpot JVM 中,Java 对象内存布局由对象头(12字节,含Mark Word与压缩Klass Pointer)、实例数据及对齐填充构成,总大小为8字节倍数。对象头支持锁状态动态复用,指针压缩使引用仅4字节,但堆超32GB时失效。实例字段按类型优先级重排序以减少间隙,最小对象大小为16字节。通过JOL工具可精准验证布局,理解锁机制、GC、伪共享等底层行为。

2301_79732484的博客 149

V8 机制、手写核心函数与 TypeScript 类型体操

或固定初始化(如数组先定长、对象先给全字段)保持类型与形状稳定;这些都比"换框架"更基础。只能处理纯数据(丢函数、Date、RegExp、循环引用报错)。生产级深拷贝要处理:原始值短路、循环引用、V8(Chrome / Node 的 JS 引擎)不是"解释一行跑一行"那么简单,它用。图:V8 执行流程——解释执行 + 热点优化,优化失败会 Deopt 回退。JS 内存自动管理,但"自动"不等于"不会漏"。是"固定间隔最多执行一次"。手写 Promise 是"懂异步"的试金石。是"停下后才执行最后一次",

qq_38468358的博客 328

Spring Boot 数据源与 MyBatis(-Plus) 自定义配置详解

本文详解 Spring Boot 中单数据源环境下 HikariCP 与 MyBatis-Plus 的自定义配置。通过手动声明 SqlSessionFactory,实现下划线转驼峰、日志输出、一级缓存策略等精细化控制。结合 HikariCP 核心参数调优(如最大连接数、连接生命周期),确保高性能与稳定性。适用于仅需访问单一数据库的场景,避免多数据源复杂性,兼顾性能与可维护性。

BADAO_LIUMANG_QIZHI的博客 195
上一篇: Stanford Algorithms学习:Clustering 2
下一篇: Reverse A Linked List
likecool21
博客等级 码龄14年 14粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值