加载中...

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....

daily leetcode - palindrome-number - !

题目地址 https://leetcode.com/problems/palindrome-number/ 题目描述 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. Example 3: Input: 10 Output: false Explanation: Reads 01 from right to left. Therefore it is not a palindrome. Follow up: Coud you....

daily leetcode - string-to-integer-atoi - !

题目地址 https://leetcode.com/problems/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, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number,....

daily leetcode - reverse-integer - !

题目地址 https://leetcode.com/problems/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 with an environment which could only store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. 思路 翻转数字问题需要注意的就是溢出问题,看了许多网上的解法,....

daily leetcode - zigzag-conversion - !

题目地址 https://leetcode.com/problems/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 I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example 1: Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNA....

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