Leetcode--easy系列3】的更多相关文章

不easy系列之(4)--考新郎 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25425    Accepted Submission(s): 9311 Problem Description 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪暂时想出了有一个有意思的节目,叫做"考新郎",详细的…
LeetCode--single-number系列 Question 1 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Soluti…
不easy系列之(3)-- LELE的RPG难题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30222 Accepted Submission(s): 12144 Problem Description 人称"AC女之杀手"的超级偶像LELE近期忽然玩起了深沉,这可急坏了众多"Cole"(LELE的粉丝,即…
版权声明:本文为博主原创文章,未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/37512659 转载请注明出处:viewmode=contents" rel="nofollow">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:pid=1465" rel="nofollow">ht…
Leetcode算法系列(链表)之删除链表倒数第N个节点 难度:中等给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点.示例:给定一个链表: 1->2->3->4->5, 和 n = 2.当删除了倒数第二个节点后,链表变为 1->2->3->5.说明:给定的 n 保证是有效的.链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list Python实现 # Definiti…
Leetcode算法系列(链表)之两数相加 难度:中等给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字.如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和.您可以假设除了数字 0 之外,这两个数都不会以 0 开头.示例:输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)输出:7 -> 0 -> 8原因:342 + 465 = 807 链接:https://le…
 *勿以浮沙筑高台* 持续更新........     题目网址:https://leetcode.com/problemset/all/?difficulty=Easy 1. Two Sum [4ms] 2. Reverse Integer [12ms] 题意:将一个32bit signed integer反转输出,如果反转之后超出32位补码范围 [-2^31,2^31-1],则输出0 思路:边取模边算结果,结果存longlong判界 3. Palindrome Number [112ms]…
Sum 系列题解 Two Sum题解 题目来源:https://leetcode.com/problems/two-sum/description/ Description Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one sol…
题目:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". Note:If there is no such windo…
本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! email: tomqianmaple@gmail.com 后续更多的easy题已经不属于Top Interview Questions,所以现在就不集中精力去做了,只做到目前的100题左右. Palindrome Linked List Lowest Common Ancestor of a Bina…
本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! email: tomqianmaple@gmail.com Two Sum Reverse Integer Palindrome Number Roman to Integer Longest Common Prefix Valid Parentheses Merge Two Sorted Lists…
题目: 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. Your goal is to reach the last index in the minimum number of j…
题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. You may not alter the values in the nodes, only…
leetcode 34 最早出现和最后出现 class Solution { public int[] searchRange(int[] nums, int target) { int []ans={-1,-1} ; for(int i=0;i<nums.length;i++){ if(nums[i]==target){ ans[0]=i; break; } } for(int j=nums.length-1;j>=0;j--){ if(nums[j]==target){ ans[1]=j;…
前言:这是关于LeetCode上面练习题C++的笔记,有些地方参考有网友的解题方法(可能有些参考没能注明,望谅解),如有需要改进的地方希望留言指教,多谢! 目录: ZigZag Conversion Reverse digits of an integer Implement atoi to convert a string to an integer Determine whether an integer is a palindrome Write a function to find th…
N-Queens 系列题解 题目来源: N-Queens N-Queens II N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. Each so…
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. leetcode的题目真是越来越经典了.比如这个题目,就是一道男默女泪的题. 一般人拿到这个题目,除非做过类似的,很难一眼找出一个方法来,更别说找一个比较优化的方法了. 首先一个难点就是,你怎么判断某个区域就是一个矩形呢? 其次,以何种方式来遍历这个2D的…
题目:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". Note:If there is no such windo…
题目: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC". Note: If there is no such w…
题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m + n) space, but sti…
题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example,  Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. 例如给出上图中的黑色部分(数组表示),让你求出蓝色部分. 这也是个神题...当…
题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()", which has length = 2. Another example i…
题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()" 解法:…
题目: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, which together with x-axis forms a conta…
题目1 1112. 每位学生的最高成绩 编写一个 SQL 查询,查询每位学生获得的最高成绩和它所对应的科目,若科目成绩并列,取 course_id 最小的一门.查询结果需按 student_id 增序进行排序. 题解 注意这里grade的外层查询需要结合group by,或者查max(grade),或者使用join查grade 代码 # Write your MySQL query statement below select student_id, min(course_id) as cour…
##题目1 626. 换座位 小美是一所中学的信息科技老师,她有一张 seat 座位表,平时用来储存学生名字和与他们相对应的座位 id. 其中纵列的 id 是连续递增的 小美想改变相邻俩学生的座位. 你能不能帮她写一个 SQL query 来输出小美想要的结果呢?   示例: +---------+---------+ | id | student | +---------+---------+ | 1 | Abbot | | 2 | Doris | | 3 | Emerson | | 4 |…
题目1 产品数据表: Products +---------------+---------+ | Column Name | Type | +---------------+---------+ | product_id | int | | new_price | int | | change_date | date | +---------------+---------+ 这张表的主键是 (product_id, change_date). 这张表的每一行分别记录了 某产品 在某个日期 更…
题目 1205. 每月交易II Transactions 记录表 +----------------+---------+ | Column Name | Type | +----------------+---------+ | id | int | | country | varchar | | state | enum | | amount | int | | trans_date | date | +----------------+---------+ id 是这个表的主键. 该表包含…
1. 题目: 编写一个函数,输入是一个无符号整数,返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量). 示例 : 输入: 11输出: 3解释: 整数 11 的二进制表示为 00000000000000000000000000001011 示例 2: 输入: 11输出: 3解释: 整数 11 的二进制表示为 00000000000000000000000000001011 class Solution { public: int hammingWeight(uint32_t n)…
1.普通数组找两个数,哈希表建立数值和下标的映射,遍历时一边判断一边添加 /* 哇,LeetCode的第一题...啧啧 */ public int [] twoSum(int[] nums, int target) { /* 两个数配合组成target 建立值和下标的映射,遍历数组时一边判断是否有另一半,一边添加新映射到哈希表 */ Map<Integer,Integer> map = new HashMap<>(); for (int i = 0; i < nums.len…