【代码随想录刷题记录】LeetCode367有效的完全平方数

题目地址 1. 思路 这个题就用二分查找的思想,比LeetCode69x的平方根要简单一些,那个还要处理开平方不是整数的情况,这个直接就按左闭右闭,middle的平方是num就返回true,否则继续迭代二分直到找到middle的平方是num的情况返回true,或者找不到跳出循环返回false. 2. 代码 class Solution {public: //左闭右闭 bool isPerfectSquare(...

leetcode面试经典150题】64. 删除排序链表中的重复元素 II(C++)

【题目描述】 给定一个已排序的链表的头 head , 删除原始链表中所有重复数字的节点,只留下不同的数字 。返回 已排序的链表 。 【示例一】 输入:head = [1,2,3,3,4,4,5]输出:[1,2,5] 【示例二】 输入:head = [1,1,1,2,3]输出:[2,3] 【提示及数据范围】 链表中节点数目在范围 [0, 300] 内-100 <= Node.val <= 100题目数据保证链...

leetcode面试经典150题】73. 从中序与后序遍历序列构造二叉树(C++)

【题目描述】 给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。 【示例一】 输入:inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]输出:[3,9,20,null,null,15,7] 【示例二】 输入:inorder = [-1],...

LeetCode //C - 18. 4Sum

109<=nums[i]<=109 − 1 0 9 < = t a r g e t < = 1 0 9 -10^9 <= target <= 10^9 −109<=target<=109 From: LeetCode Link: 18. 4Sum Solution: Ideas: Sorting: The array is sorted to allow efficient searching and to ea...

Leetcode】vector刷题

🔥个人主页:Quitecoder 🔥专栏:Leetcode刷题 目录 1.只出现一次的数字2.杨辉三角3.删除有序数组中的重复项4.只出现一次的数字II5.只出现一次的数字III6.电话号码的字母组合 1.只出现一次的数字 这道题很简单,我们只需要遍历一遍数组,利用异或操作的性质(一个数与自身异或结果为0,任何数与0异或还是其本身) class Solution {public: int singleNumb...

LeetCode //C - 38. Count and Say Medium Topics Companies

th} nth term of the count-and-say sequence.   Example 1: Example 2: Constraints: 1 <= n <= 30 From: LeetCode Link: 38. Count and Say Solution: Ideas: Base Case: If n is 1, the function returns the string “1”,...

leetcode面试经典150题】74. 填充每个节点的下一个右侧节点指针 II(C++)

【题目描述】 给定一个二叉树: struct Node { int val; Node *left; Node *right; Node *next;} 填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL 。 初始状态下,所有 next 指针都被设置为 NULL 。 【示例一】 输入:root = [1,2,3,4,5,null,7]...

leetcode面试经典150题】62. K 个一组翻转链表(C++)

【题目描述】 给你链表的头节点 head ,每 k 个节点一组进行翻转,请你返回修改后的链表。 k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序。 你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。 【示例一】 输入:head = [1,2,3,4,5], k = 2输出:[2,1,4,3,5] 【示例二】 输入:head = [1,2...

LeetCode //C - 37. Sudoku Solver

= 9board[i][j] is a digit or ‘.’.It is guaranteed that the input board has only one solution. From: LeetCode Link: 29. Divide Two Integers Solution: Ideas: Sudoku Rules: To solve Sudoku, the code must respect...

LeetCode //C - 29. Divide Two Integers

2 31 − 1 -2^{31} <= dividend, divisor <= 2^{31} - 1 −231<=dividend,divisor<=231−1divisor != 0 From: LeetCode Link: 29. Divide Two Integers Solution: Ideas: Handle Signs: Compute the sign of the result based o...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.013504(s)
2024-04-29 13:42:24 1714369344