相交链表(LeetCode

题目 解题 class ListNode: def __init__(self, x): self.val = x self.next = None def getIntersectionNode(headA, headB): """ 找到两个单链表相交的起始节点。 参数: headA (ListNode): 第一个链表的头节点。 headB (ListNode): 第二个链表的头节点。 返回值: ListNod...

LeetCode //C - 260. Single Number III

31<=nums[i]<=231−1Each integer in nums will appear twice, only two integers will appear once. From: LeetCode Link: 260. Single Number III Solution: Ideas: Use of Unsigned Type: By casting xor_result to an uns...

LeetCode热题100》---<哈希三道>

第一道:两数之和(简单) class Solution { public int[] twoSum(int[] nums, int target) { int left = 0,right = nums.length-1; Arrays.sort(nums); while (left < right){ if(nums[left] + nums[right] < target) { left++; }else ...

分隔链表(LeetCode

题目 解题 class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def partition(head: ListNode, x: int) -> ListNode: # 创建两个虚拟头节点 smaller_head = ListNode(0) greater_head = ListNode(0)...

LeetCode //C - 258. Add Digits

mple 1: Example 2: Constraints: 0 < = n u m < = 2 31 − 1 0 <= num <= 2^{31} - 1 0<=num<=231−1 From: LeetCode Link: 258. Add Digits Solution: Ideas: 1. Digital Root Concept: The digital root of a number is the...

LeetCode 0002】【链表】两数相加

Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers a...

LeetCode //C - 237. Delete Node in a Linked List

each node in the list is unique.The node to be deleted is in the list and is not a tail node. From: LeetCode Link: 237. Delete Node in a Linked List Solution: Ideas: Check for edge cases: The function first c...

LeetCode226. 翻转二叉树

LeetCode题目链接:https://leetcode.cn/problems/invert-binary-tree/题目叙述:给你一棵二叉树的根节点 root ,翻转这棵二叉树,并返回其根节点。 输入:root = [4,2,7,1,3,6,9]输出:[4,7,2,9,6,3,1] 示例 2: 输入:root = [2,1,3]输出:[2,3,1]示例 3:输入:root = []输出:[]...

LeetCode //C - 241. Different Ways to Add Parentheses

or ‘+’, ‘-’, and ‘*’.All the integer values in the input expression are in the range [0, 99]. From: LeetCode Link: 241. Different Ways to Add Parentheses Solution: Ideas: isSingleNumber Check: Added a functio...

LeetCode 0231】【位运算】2的N次方

Power of Two Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2^x. Example 1: **Input:** n = 1**O...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.011289(s)
2024-11-21 18:02:08 1732183328