LeetCode|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-30C++实现LeetCode(73.矩阵赋零)
[LeetCode] 73.Set Matrix Zeroes 矩阵赋零Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea....
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-03LeetCode:交替打印【1115】
LeetCode:交替打印【1115】题目描述我们提供一个类:class FooBar {public void foo() { for (int i = 0; i < n; i++) { print("foo"); }}public void bar() { for (int i = 0; i < n; i++) { print("bar"); }}}两个不同的线程将会共用一个 FooBar 实例。其中一个线程将会调用 foo() 方法,另一个线程将会调用 bar(...
2022-06-03C++实现LeetCode(38.计数和读法)
[LeetCode] 38. Count and Say 计数和读法The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off...
2022-02-02C++实现LeetCode(93.复原IP地址)
[LeetCode] 93.Restore IP Addresses 复原IP地址Given a string containing only digits, restore it by returning all possible valid IP address combinations.Example:Input: "25525511135"Output: ["255.255.11.135", "255.255.111.35"]这道题要求是复原IP地址,IP地址对我们并不陌生,就算我们不是学CS的,只...
2022-02-02C++实现LeetCode(135.分糖果问题)
[LeetCode] 135.Candy 分糖果问题There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating ...
2022-02-02C++实现LeetCode(75.颜色排序)
[LeetCode] 75. Sort Colors 颜色排序Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to repre...
2022-02-02C++实现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(55.跳跃游戏)
[LeetCode] 55. Jump Game 跳跃游戏Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last in...
2022-01-16如何在VSCode中调试LeetCode代码
近期收到不少小伙伴的求助,希望知道如何在 VS Code 中调试 LeetCode 代码。通常来说,为了调试本地代码,我们需要安装相关的语言支持插件。本文中,我们就以调试 LeetCode Java 代码为例,给大家介绍本地调试 LeetCode 代码的常用套路。 想要了解如何在 VS Code 中刷题的小伙伴,可以移步: ...
2022-05-31C++实现LeetCode(57.插入区间)
[LeetCode] 57. Insert Interval 插入区间Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Input: intervals = [...
2022-02-02C++实现LeetCode(71.简化路径)
[LeetCode] 71.Simplify Path 简化路径Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did you consider the case where path = "/../"? In...
2022-02-02C++实现LeetCode(13.罗马数字转化成整数)
[LeetCode] 13. Roman to Integer 罗马数字转化成整数Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...
2022-01-16C++实现LeetCode(148.链表排序)
[LeetCode] 148. Sort List 链表排序Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->0->3->4->5常见排序方法有很多,插入排序,选择排序,堆排序,快速排序,冒泡排序,归并排序,桶排序等等。。它们的时间复杂度不尽相同...
2022-02-01C++实现LeetCode(47.全排列之二)
[LeetCode] 47. Permutations II 全排列之二Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[[1,1,2],[1,2,1],[2,1,1]]这道题是之前那道 Permutations 的延伸,由于输入数组有可能出现重复数字,如果按照之前的算法运算,会有重复排列产生,我们...
2022-02-02C++实现LeetCode(113.二叉树路径之和之二)
[LeetCode] 113. Path Sum II 二叉树路径之和之二Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5/ \4 8/ / \11 13 4/ \ / \7 2 5 1ret...
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(59.螺旋矩阵之二)
[LeetCode] 59. Spiral Matrix II 螺旋矩阵之二Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ]]此题跟之前那道 Spiral Matrix 本质上没什么区别,就相当于个类似逆运算的过程,这道题是要按螺旋的顺...
2022-02-02C++实现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(83.移除有序链表中的重复项)
[LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1->2->3这道题让我们移除给定有序链表的重复项,那么可以遍...
2022-02-02C++实现LeetCode(11.装最多水的容器)
[LeetCode] 11. 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). Find two lines, ...
2022-01-16C++实现LeetCode(676.实现神奇字典)
[LeetCode] 676.Implement Magic Dictionary 实现神奇字典Implement a magic directory with buildDict, and search methods.For the method buildDict, you'll be given a list of non-repetitive words to build a dictionary.For the method search, you'll be given a word, and...
2022-02-01