
leetcode
leo_weile
这个作者很懒,什么都没留下…
展开
-
leetcode 2. 两数相加
leetcode2. 两数相加1、题目描述给你两个非空 的链表,表示两个非负的整数。它们每位数字都是按照逆序的方式存储的,并且每个节点只能存储一位数字。请你将两个数相加,并以相同形式返回一个表示和的链表。你可以假设除了数字 0 之外,这两个数都不会以 0开头。示例 1:输入:l1 = [2,4,3], l2 = [5,6,4]输出:[7,0,8]解释:342 + 465 = 807.示例 2:输入:l1 = [0], l2 = [0]输出:[0]示...原创 2021-01-25 21:23:29 · 210 阅读 · 0 评论 -
leetcode 1 两数之和
leetcode 1两数之和1、题目描述:给定一个整数数组 nums和一个整数目标值 target,请你在该数组中找出 和为目标值 的那两个整数,并返回它们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。你可以按任意顺序返回答案。示例 1:输入:nums = [2,7,11,15], target = 9输出:[0,1]解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。示例 2:输入:nums = ...原创 2021-01-24 22:37:52 · 94 阅读 · 0 评论 -
leetcode 402. 移掉K位数字 题解
题目描述给定一个以字符串表示的非负整数num,移除这个数中的 k 位数字,使得剩下的数字最小。注意:num 的长度小于 10002 且≥ k。num 不会包含任何前导零。示例 1 :输入: num = "1432219", k = 3输出: "1219"解释: 移除掉三个数字 4, 3, 和 2 形成一个新的最小的数字 1219。示例 2 :输入: num = "...原创 2020-01-10 15:26:15 · 281 阅读 · 0 评论 -
leetcode 摆动序列 题解
题目描述如果连续数字之间的差严格地在正数和负数之间交替,则数字序列称为摆动序列。第一个差(如果存在的话)可能是正数或负数。少于两个元素的序列也是摆动序列。例如,[1,7,4,9,2,5] 是一个摆动序列,因为差值 (6,-3,5,-7,3)是正负交替出现的。相反, [1,4,7,2,5]和[1,7,4,5,5] 不是摆动序列,第一个序列是因为它的前两个差值都是正数,第二个序列是因为...原创 2020-01-09 10:04:30 · 196 阅读 · 0 评论 -
leetcode 加油站 题解
题目描述在一条环路上有N个加油站,其中第i个加油站有汽油gas[i]升。你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1个加油站需要消耗汽油cost[i]升。你从其中的一个加油站出发,开始时油箱为空。如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。说明:如果题目有解,该答案即为唯一答案。输入数组均为非空数组,且长度相同。...原创 2020-01-09 09:27:30 · 538 阅读 · 0 评论 -
leetcode K 个一组翻转链表 题解
题目描述给你一个链表,每k个节点一组进行翻转,请你返回翻转后的链表。k是一个正整数,它的值小于或等于链表的长度。如果节点总数不是k的整数倍,那么请将最后剩余的节点保持原有顺序。示例 :给定这个链表:1->2->3->4->5当k= 2 时,应当返回: 2->1->4->3->5当k= 3 时,应当返回: ...原创 2019-11-17 11:45:37 · 116 阅读 · 0 评论 -
leetcode 复制带随机指针的链表 题解
题目描述给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。要求返回这个链表的深拷贝。示例:输入:{"$id":"1","next":{"$id":"2","next":null,"random":{"$ref":"2"},"val":2},"random":{"$ref":"2"},"val":1}解释:节点 1 的值是 1,...原创 2019-11-17 10:54:55 · 172 阅读 · 0 评论 -
leetcode Maximum Subarray题解
题目描述:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Ex...原创 2019-02-15 13:44:11 · 128 阅读 · 0 评论 -
leetcode Length of Last Word题解
题目描述:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word i...原创 2019-02-15 13:47:12 · 160 阅读 · 0 评论 -
leetcode Plus One题解
题目描述:Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each ...原创 2019-02-15 14:26:22 · 161 阅读 · 0 评论 -
leetcode Add Binary题解
题目描述:Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100...原创 2019-02-15 15:26:42 · 104 阅读 · 0 评论 -
leetcode Best Time to Buy and Sell Stockt题解
题目描述:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the ...原创 2019-02-21 15:33:40 · 90 阅读 · 0 评论 -
leetcode Best Time to Buy and Sell Stock II题解
题目描述:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e.,...原创 2019-02-21 16:05:08 · 156 阅读 · 0 评论 -
leetcode Sqrt(x)题解
题目描述:Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated a...原创 2019-02-15 20:20:47 · 176 阅读 · 0 评论 -
leetcode Climbing Stairs题解
题目描述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a p...原创 2019-02-15 20:44:04 · 137 阅读 · 0 评论 -
leetcode Valid Palindrome题解
题目描述:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome....原创 2019-02-21 19:15:09 · 143 阅读 · 0 评论 -
leetcode Single Number题解
题目描述:Given a non-empty 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 wit...原创 2019-02-21 19:25:48 · 154 阅读 · 0 评论 -
leetcode Linked List Cycle题解
中文描述:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where ...原创 2019-02-21 19:39:15 · 140 阅读 · 0 评论 -
leetcode Min Stack题解
题目描述:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top(...原创 2019-02-21 20:17:36 · 151 阅读 · 0 评论 -
leetcode Intersection of Two Linked Lists题解
题目描述:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1. Example 1:...原创 2019-02-21 21:16:12 · 158 阅读 · 0 评论 -
leetcode Two Sum II - Input array is sorted题解
题目描述:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two n...原创 2019-02-22 13:39:07 · 85 阅读 · 0 评论 -
leetcode Excel Sheet Column Title题解
题目描述:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA ...原创 2019-02-22 14:12:33 · 137 阅读 · 0 评论 -
leetcode two-sum题解
题目描述: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 solution, and you may not use the ...原创 2019-02-11 14:23:04 · 138 阅读 · 1 评论 -
leetcode reverse-integer题解
题目描述:Given a 32-bit signed integer, reverse digits of an integer.note:Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − ...原创 2019-02-11 14:31:54 · 164 阅读 · 0 评论 -
leetcode palindrome-number题解
题目描述:Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.汉语理解:判断一个数字是不是回文数字,其中题目给的提示中说明负数不是回文数字。解题思路:(1)负数不是回文数 (...原创 2019-02-11 14:38:22 · 124 阅读 · 0 评论 -
leetcode Majority Element题解
题目描述:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority eleme...原创 2019-02-22 16:24:01 · 106 阅读 · 0 评论 -
leetcode 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 ...原创 2019-02-12 10:37:52 · 165 阅读 · 0 评论 -
leetcode longest-common-prefix题解
题目描述:Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".汉语理解:给出一个字符串数组,求字符串数组中字符的公共前缀。解题思路:将字符串数组的元素排序,...原创 2019-02-12 10:57:29 · 118 阅读 · 0 评论 -
leetcode valid-parentheses题解
题目描述:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type...原创 2019-02-12 11:23:58 · 129 阅读 · 0 评论 -
leetcode Happy Number题解
题目描述:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the sq...原创 2019-02-27 16:56:04 · 163 阅读 · 0 评论 -
leetcode 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->3Out...原创 2019-02-18 11:54:46 · 103 阅读 · 0 评论 -
leetcode Merge Sorted Array题解
题目描述:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively. You may ass...原创 2019-02-18 12:10:52 · 95 阅读 · 0 评论 -
leetcode Remove Linked List Elements题解
题目描述:Remove all elements from a linked list of integers that have valueval.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5中文理解:给定一个链表,给定一个值,若...原创 2019-02-27 20:13:08 · 145 阅读 · 0 评论 -
leetcode Count Primes题解
题目描述:Count the number of prime numbers less than a non-negative number,n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.中文理解:给定一个数字n,求出在...原创 2019-02-27 20:40:14 · 147 阅读 · 0 评论 -
leetcode Isomorphic Strings题解
题目描述:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a character must be replaced with a...原创 2019-02-27 20:59:13 · 161 阅读 · 0 评论 -
leetcode Reverse Linked List题解
题目描述:Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL中文理解:反转一个给定链表。解题思路:使用头插法,将原始链表的后面的节点不断插入到头结点的后面。代码(java):/...原创 2019-02-27 21:05:30 · 132 阅读 · 0 评论 -
leetcode Contains Duplicate题解
题目描述:Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every el...原创 2019-02-27 22:48:56 · 161 阅读 · 0 评论 -
leetcode Contains Duplicate II题解
题目描述:Given an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and theabsolutedifference betweeniandjis at m...原创 2019-02-28 10:12:07 · 165 阅读 · 0 评论 -
leetcode merge-two-sorted-lists题解
题目描述:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.汉语理解:将两个有序链表合并为一个链表,并且新链表是由原来两个链表的节点组成的。解题思路:这个题目的...原创 2019-02-13 10:10:57 · 132 阅读 · 0 评论 -
leetcode Remove Duplicates from Sorted Array题解
题目描述:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modi...原创 2019-02-13 10:23:21 · 109 阅读 · 0 评论