![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
青盏
这个作者很懒,什么都没留下…
展开
-
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 “”.Example 1:Input: [“flower”,“flow”,“flight”]Output:...原创 2019-03-03 14:12:42 · 89 阅读 · 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. Example: Given nums = [2原创 2016-09-28 16:58:10 · 508 阅读 · 0 评论 -
LeetCode之Longest Substring Without Repeating Characters 最长无重复子串
一、题目Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, wit原创 2016-10-10 18:12:56 · 382 阅读 · 0 评论 -
LeetCode Add Two Numbers 两个链表数相加
一、题目You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a l原创 2016-10-09 11:35:44 · 301 阅读 · 0 评论 -
LeetCode:4. Median of Two Sorted Arrays 两个排序数组的中值
1、 简单合并,排序,取中值class Solution {public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int *it; int m = nums1.size()?nums1.size():0; int n = nums2.原创 2017-11-08 22:09:36 · 304 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring
一、试题Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: “babad”Output: “bab”Note: “aba” is also a valid answer. Example:In原创 2017-11-09 11:32:17 · 425 阅读 · 0 评论 -
LeetCode 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 N A P L S I原创 2017-11-09 14:50:06 · 190 阅读 · 0 评论 -
LeetCode String to Integer (atoi)
一、试题Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cas原创 2017-12-08 22:36:05 · 228 阅读 · 0 评论 -
LeetCode Reverse Integer
一、题目Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123 Output: 321 Example 2:Input: -123 Output: -321 Example 3:Input: 120 Output: 21 Note: Assume we are dealing w原创 2017-12-06 18:46:04 · 389 阅读 · 0 评论 -
LeetCode Palindrome Number
试题Determine whether an integer is a palindrome. Do this without extra space.代码// 计算出数字的两边的单个数字进行比较static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0;}原创 2018-01-17 15:00:02 · 226 阅读 · 0 评论 -
LeetCode 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...原创 2019-03-02 16:24:05 · 107 阅读 · 0 评论 -
LeetCode Integer to Roman
试题Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...转载 2019-03-02 16:41:49 · 103 阅读 · 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-03-02 17:08:52 · 151 阅读 · 0 评论 -
LeetCode 3Sum 三数求和固定值
试题:Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not co...原创 2019-03-03 15:34:25 · 207 阅读 · 0 评论 -
LeetCode 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 wo...原创 2019-03-03 19:29:34 · 124 阅读 · 0 评论 -
LeetCodeLetter Combinations of a Phone Number 号码的组合形式
试题:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is ...转载 2019-03-03 19:57:22 · 224 阅读 · 0 评论 -
LeetCode 4Sum 数组中多数求和等于目标值
试题:Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of...原创 2019-03-04 15:09:50 · 516 阅读 · 0 评论 -
LeetCode:Linked List Cycle II 链表回环入口处
试题:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the position (...转载 2019-03-10 17:11:01 · 177 阅读 · 0 评论 -
LeetCode: 67. 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”Examp...原创 2019-03-19 15:03:48 · 123 阅读 · 0 评论 -
LeetCode: Valid Palindrome II 字符串能否成回文
试题:Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1:Input: “aba”Output: TrueExample 2:Input: “abca”Output: TrueExplanation...原创 2019-03-15 10:52:11 · 149 阅读 · 0 评论 -
LeetCod: 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 assume th...原创 2019-03-15 11:07:30 · 114 阅读 · 0 评论 -
LeetCode: 141. 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 tail...原创 2019-03-15 11:19:56 · 103 阅读 · 0 评论 -
LeetCode : Longest Word in Dictionary through Deleting 字典中的最大串
试题:Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, r...原创 2019-03-15 14:24:13 · 95 阅读 · 0 评论 -
LeetCode: 345. Reverse Vowels of a String 反转字符串中元音字母
试题:Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: “hello”Output: “holle”Example 2:Input: “leetcode”Output: “leotcede”Note:The vowels do...原创 2019-03-15 14:43:38 · 150 阅读 · 0 评论 -
LeetCode: 215. Kth Largest Element in an Array 数组中第k大元素
试题:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Ex...原创 2019-03-15 16:12:30 · 186 阅读 · 0 评论 -
LeetCode: 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...原创 2019-03-15 21:21:46 · 617 阅读 · 0 评论 -
LeetCode : 347. Top K Frequent Elements 根据频率选取topk元素
试题:Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:You may ...转载 2019-03-16 14:53:15 · 188 阅读 · 0 评论 -
LeeCode : 451. Sort Characters By Frequency 按频率给字符排序
试题:Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:“tree”Output:“eert”Explanation:‘e’ appears twice while ‘r’ and ‘t’ both appear once.So ‘e’ ...转载 2019-03-16 15:08:06 · 141 阅读 · 0 评论 -
LeetCode : 455. Assign Cookies 分饼干
试题:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a...转载 2019-03-16 16:47:28 · 146 阅读 · 0 评论 -
LeetCode : 69. Sqrt(x) 开方
试题:mplement 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 and onl...原创 2019-03-16 19:29:51 · 156 阅读 · 0 评论 -
LeetCode: Different Ways to Add Parentheses 给公式加括号
试题:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1:I...转载 2019-03-16 20:25:20 · 141 阅读 · 0 评论 -
LeetCode : Sum of Square Numbers 两个数的平方和
试题:Given a non-negative integer c, your task is to decide whether there’re two integers a and b such that a2 + b2 = c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5Example 2:Input...原创 2019-03-13 14:23:25 · 350 阅读 · 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 numbe...原创 2019-03-13 14:09:12 · 120 阅读 · 0 评论 -
LeetCod: 64. Minimum Path Sum 最小路径和
试题:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right a...原创 2019-03-22 22:26:33 · 99 阅读 · 0 评论 -
LeetCode : 122. 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., buy ...原创 2019-03-29 21:43:39 · 188 阅读 · 0 评论 -
LeetCode : 121. Best Time to Buy and Sell Stock 股票的最大收益
试题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 stock...原创 2019-03-29 22:07:35 · 119 阅读 · 0 评论 -
LeetCode: 413. Arithmetic Slices 数组中等差子序列的个数
试题:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequen...转载 2019-03-26 14:22:45 · 177 阅读 · 0 评论 -
LeetCode:303. Range Sum Query - Immutable 数组范围内求和
试题:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sum...原创 2019-03-23 10:44:16 · 112 阅读 · 0 评论 -
LeetCode: 392. Is Subsequence 是否是子序列
试题:Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) stri...原创 2019-03-26 15:52:38 · 132 阅读 · 0 评论 -
LeetCode:343. Integer Break 拆分整数保持乘积最大
试题:Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: ...原创 2019-03-23 13:39:27 · 395 阅读 · 0 评论