加载中...

存档 - 2020 年 01 月

21 篇文章

daily leetcode - remove-nth-node-from-end-of-list - !

题目地址 https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 题目描述 Given a linked list, remove the n th node from the end of list and return its head. For example, Given linked list: **1- >2->3->4->5**, and **_n_ = 2**. After removing the second node from the end, the linked list becomes **1- >2->3->5**. Note: Given n will always be valid. Try to do this in one pass. Follow up: Could you do this in one pass? 思路 这道题让我们移除链表倒数第 N 个节点,限定 n 一定是有效的,即 n 不会大于链表中的元素总数。还有题目要求....

daily leetcode - 4sum - !

题目地址 https://leetcode.com/problems/4sum/ 题目描述 Given an array S of n integers, are there elements a , b , c , and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a quadruplet ( a , b , c , d ) must be in non-descending order. (ie, a ≤ b ≤ c ≤ d ) The solution set must not contain duplicate quadruplets. For example, given array S = {1 0 -1 0 -2 2}, and target = 0. A solution set is: (-1, 0, 0, 1) (-2, -1, 1, 2) (-2....

daily leetcode - letter-combinations-of-a-phone-number - !

题目地址 https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 题目描述 Given a string containing digits from 2-9inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example: Input: "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. Note: Although the above answer is in lexicographical order, your answer could be in ....

daily leetcode - 3sum-closest - !

题目地址 https://leetcode.com/problems/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 solution. Example: Given array nums = [-1, 2, 1, -4], and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). 思路 这道题让我们求最接近给定值的三数之和,是在之前那道 3Sum 的基础上又增加了些许难度,那么这道题让返回这个最接近于给定值的值,即要保证当前三数和跟给定值之间的差的绝对值最小,所以需要定....

daily leetcode - 3sum - !

题目地址 https://leetcode.com/problems/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 ≤ b ≤ c ) The solution set must not contain duplicate triplets. For example, given array S = {-1 0 1 2 -1 -4}, A solution set is: (-1, 0, 1) (-1, -1, 2) 思路 这道题让我们求三数之和,比之前那道 Two Sum 要复杂一些,博主考虑过先 fix 一个数,然后另外两个数....

daily leetcode - longest-common-prefix - !

题目地址 https://leetcode.com/problems/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: "fl" Example 2: Input: ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings. Note: All given inputs are in lowercase letters a-z. 思路 这道题让我们求一系列字符串的共同前缀,没有什么特别的技巧,无脑查找即可,定义两个变量 i 和 j,其中 i 是遍历搜索字....

daily leetcode - roman-to-integer - !

题目地址 https://leetcode.com/problems/roman-to-integer/ 题目描述 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X+ II. The number twenty seven is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is ....

daily leetcode - integer-to-roman - !

题目地址 https://leetcode.com/problems/integer-to-roman/ 题目描述 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is....

daily leetcode - container-with-most-water - !

题目地址 https://leetcode.com/problems/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, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container and n is at least 2. The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7....

daily leetcode - regular-expression-matching - !

题目地址 https://leetcode.com/problems/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 matching should cover the entire input string (not partial). Note: s could be empty and contains only lowercase letters a-z. p could be empty and contains only lowercase letters a-z, and characters like . or *. Example 1: Inpu....

avatar
Lonus Lan
It's better to burn out than to fade away!
公告
暂无更新通知!
最新文章
网站资讯
文章数目 :
156
已运行时间 :
0 天
本站在线访客数 :
0
本站总访问量 :
0