LeetCode小白需要援助
兄弟们,刷java的LeetCode题,为什么·总是感觉代码不全比如这种给你一个 32 位的有符号整数 x ,返回 x 中每位上的数字反转后的结果。如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1] ,就返回 0。假设环境不允许存储 64 位整数(有符号或无符号)。代码是这样的class Solution {public int...
2021-03-09LeetCode|371.两整数之和
题目描述等级: 简单不使用运算符 + 和 - ,计算两整数a 、b之和。示例1:输入: a = 1, b = 2输出: 3示例2:输入: a = -2, b = 3输出: 1思路对于位运算的考察。在位运算中,异或操作获取的是两个数的无进位和,异或:相同为0,不同为1。如,2^3 0010^ 0011------- 0001我们知道,2+3=5,5的二进制是...
2022-05-30【一起刷LeetCode】Z字形变换
题目描述将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下:之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"LCIRETOESIIGEDHN"。请你实现这个将字符串进行指定行数变换的函数:string convert(str...
2022-05-28C++实现LeetCode(36.验证数独)
[LeetCode] 36. Valid Sudoku 验证数独Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9without repetition.Each column must contain the digits 1-9 without rep...
2022-02-02【LeetCode】Word Pattern
我在 LeetCode 上练习 Word Pattern(题目连接点这里),写的程序放在本地VS2008上跑如下实例:pattern = "abba", str = "dog cat cat fish" should return false.没有问题,返回的是false,但是放在LeetCode 上提交,提示错误,错误如下:代码如下:class Solution {public: bool wordPattern(string pattern, string str) { const ...
2021-07-10小白求解决LeetCode存在重复问题
题目描述给定一个整数数组,判断是否存在重复元素。如果任何值在数组中出现至少两次,函数返回 true。如果数组中每个元素都不相同,则返回 false。题目来源及自己的思路自己思路:两次循环,将相同的元素放到新数组中,通过判断新数组是否为空来判断是否存在重复。相关代码// 请把代码文本...
2021-06-26使用Clion刷LeetCode的方法
首先创建一个project,我这里取名为LeetCode。安装leetcode editor插件,File–>Settings–>Plugins,直接搜索leetcode就出来了,安装完了记得重启一下IDE。设置LeetCode用户名和密码CodeFileName:$!{question.frontendQuestionId}-${question.titleSlug}CodeTemplate:${question.content}\#include<bits/stdc++.h>using namespac...
2022-02-03C++实现LeetCode(163.缺失区间)
[LeetCode] 163. Missing Ranges 缺失区间Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, upper], return its missing ranges.Example:Input: nums = [0, 1, 3, 50, 75], lower = 0 and upper = 99,Output: ["2", "4->49", ...
2022-02-01C++实现LeetCode(32.最长有效括号)
[LeetCode] 32. Longest Valid Parentheses 最长有效括号Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid parentheses sub...
2022-02-02C++实现LeetCode(203.移除链表元素)
[LeetCode] 203.Remove Linked List Elements 移除链表元素Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special thanks to @mithmatt for ad...
2022-02-01C++实现LeetCode(15.三数之和)
[LeetCode] 15. 3Sum 三数之和Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ ...
2022-01-17C++实现LeetCode(56.合并区间)
[LeetCode] 56. Merge Intervals 合并区间Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].Exam...
2022-02-02如何在VSCode中调试LeetCode代码
近期收到不少小伙伴的求助,希望知道如何在 VS Code 中调试 LeetCode 代码。通常来说,为了调试本地代码,我们需要安装相关的语言支持插件。本文中,我们就以调试 LeetCode Java 代码为例,给大家介绍本地调试 LeetCode 代码的常用套路。 想要了解如何在 VS Code 中刷题的小伙伴,可以移步: ...
2022-05-31LeetCode:链表中是否存在环的证明问题。
判断链表中是否存在环,通常使用双指针的方式,因为快指针、慢指针最终都会在环中相遇,但如何证明这两个指针一定会相遇呢,推倒过程如下:我的疑问是:算式(3)是通过怎样的方式转换为算式(4)的呢?回答(a + b) % c = (a % c + b % c) % c这个证明把 () % c 部分约掉了。...
2020-08-04C++实现LeetCode(87.搅乱字符串)
[LeetCode] 87. Scramble String 搅乱字符串Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great/ \gr eat/ \ / \g r e at/ \a...
2022-02-02C++实现LeetCode(49.群组错位词)
[LeetCode] 49. Group Anagrams 群组错位词Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[["ate","eat","tea"],["nat","tan"],["bat"]]Note:All inputs will be in lowercase.The order of your output ...
2022-02-02SQL实现LeetCode(176.第二高薪水)
[LeetCode] 176.Second Highest Salary 第二高薪水Write a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For example, given the above Emplo...
2021-12-21C++实现LeetCode(164.求最大间距)
[LeetCode] 164. Maximum Gap 求最大间距Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Return 0 if the array contains less than 2 elements.Example 1:Input: [3,6,9,1]Output: 3Explanation: The sorted form of ...
2022-02-01C++实现LeetCode(179.最大组合数)
[LeetCode] 179. Largest Number 最大组合数Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: "210"Example 2:Input: [3,30,34,5,9]Output: "9534330"Note: The result may be very large, so you nee...
2022-02-01C++实现LeetCode(149.共线点个数)
[LeetCode] 149. Max Points on a Line 共线点个数Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.Example 1:Input: [[1,1],[2,2],[3,3]]Output: 3Explanation:^|| o| o| o +------------->0 1 2 3 4Examp...
2022-02-01C++实现LeetCode(8.字符串转为整数)
[LeetCode] 8. String to Integer (atoi) 字符串转为整数Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character,...
2022-01-17C++实现LeetCode(67.二进制数相加)
[LeetCode] 67. Add Binary 二进制数相加Given two binary strings a and b, return their sum as a binary string.Example 1:Input: a = "11", b = "1"Output: "100"Example 2:Input: a = "1010", b = "1011"Output: "10101"Constraints:1 <= a.length, b.length <= 104a and b con...
2022-02-02C++实现LeetCode(16.最近三数之和)
[LeetCode] 16. 3Sum Closest 最近三数之和Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solut...
2022-02-02C++实现LeetCode(6.字型转换字符串)
[LeetCode] 6. ZigZag Conversion 之字型转换字符串The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY I RAnd then ...
2022-01-17C++实现LeetCode(10.正则表达式匹配)
[LeetCode] 10. Regular Expression Matching 正则表达式匹配Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matchin...
2022-01-17