随笔分类 -  LeetCode

摘要: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 阅读全文
posted @ 2017-02-16 22:29 Strugglion 阅读(2469) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings. 解法: 广度优先搜索:先比较所有字符串的第一个字符,然后比较第二个。。。。如果某一行没有了(说明其为最短的单词)或者遇到不匹配 阅读全文
posted @ 2017-02-16 16:15 Strugglion 阅读(153) 评论(0) 推荐(0)
摘要:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解法: 只要考虑两种情况即可: 第一,如果当前数字是最后一个数字,或者之后的数字比它 阅读全文
posted @ 2017-02-16 00:26 Strugglion 阅读(159) 评论(0) 推荐(0)
摘要:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 解释: 罗马数字采用七个罗马字母作数字、即Ⅰ(1)、X(10)、C(100)、M(1 阅读全文
posted @ 2017-02-15 22:51 Strugglion 阅读(206) 评论(0) 推荐(0)
摘要: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 endpo 阅读全文
posted @ 2017-02-15 17:09 Strugglion 阅读(166) 评论(0) 推荐(0)
摘要:Implement regular expression matching with support for '.' and '*'. 解法1: 这道题中的*表示*之前的那个字符可以有0个,1个或是多个,就是说,字符串a*b,可以表示b或是aaab,即a的个数任意;字符串.*b,可以表示b或是xyz 阅读全文
posted @ 2017-02-14 22:11 Strugglion 阅读(264) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thi 阅读全文
posted @ 2017-02-13 00:28 Strugglion 阅读(168) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2017-02-12 23:57 Strugglion 阅读(195) 评论(0) 推荐(0)
摘要:Reverse digits of an integer. Example1: Example2: Have you thought about this? Here are some good questions to ask before coding. Bonus points for you 阅读全文
posted @ 2017-02-12 17:58 Strugglion 阅读(194) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2017-02-12 15:56 Strugglion 阅读(190) 评论(0) 推荐(0)
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 求字符串中的最大回文子串(从左往右和从右往左读一样的子串)。 Exa 阅读全文
posted @ 2017-02-12 00:51 Strugglion 阅读(318) 评论(0) 推荐(0)
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh 阅读全文
posted @ 2017-02-10 19:14 Strugglion 阅读(538) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: 解法: 建立一个大小为256整形数组,用来记录每个字符上一次出现的位置。longest记录最长的子串长度, 阅读全文
posted @ 2017-02-09 22:26 Strugglion 阅读(166) 评论(0) 推荐(0)
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai 阅读全文
posted @ 2017-02-09 18:58 Strugglion 阅读(247) 评论(0) 推荐(0)
摘要: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 ex 阅读全文
posted @ 2017-02-09 16:05 Strugglion 阅读(406) 评论(0) 推荐(0)