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...

LeetCode:2956. 找到两个数组中的公共元素 + 模拟计数】

🍔 目录 🚩 题目链接⛲ 题目描述🌟 求解思路&实现代码&运行结果⚡ 模拟计数🥦 求解思路🥦 实现代码🥦 运行结果 💬 共勉 🚩 题目链接 2956. 找到两个数组中的公共元素 ⛲ 题目描述 给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,它们分别含有 n 和 m 个元素。 请你计算以下两个数值: 统计 0 <= i < n 中的下标 i ,满足 nums1[i] 在 nums2 中 至少 出...

LeetCode:721. 账户合并 + 哈希表 + DFS】

🍔 目录 🚩 题目链接⛲ 题目描述🌟 求解思路&实现代码&运行结果⚡ 哈希表 + DFS🥦 求解思路🥦 实现代码🥦 运行结果 💬 共勉 🚩 题目链接 721. 账户合并 ⛲ 题目描述 给定一个列表 accounts,每个元素 accounts[i] 是一个字符串列表,其中第一个元素 accounts[i][0] 是 名称 (name),其余元素是 emails 表示该账户的邮箱地址。 现在,我们想合并这些账户。...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.007140(s)
2024-10-23 03:09:45 1729624185