Stephen.Ri Blog

You are waiting for a train, a train that will take you far away!

[LeetCode]14. Longest Common Prefix

  "查找多个字符串公共前缀问题"

Description Write a function to find the longest common prefix string amongst an array of strings. Discussion 查找公共前缀的问题。只需要从头开始把每个数组的第i个字符进行比较,有不一样的就跳出循环即可。另外需要注意特殊情况处理。 算法的时间复杂度为O(n)。 C++ Cod...

[LeetCode]13. Roman to Integer

  "罗马数字转阿拉伯数字"

Description Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. Discussion 罗马数字转成阿拉伯数字。我们需要知道罗马数字的构成规则。罗马数字通过7个不同字母的重复或组合,能够表示出1到3999的所有数...

[LeetCode]22. Merge k Sorted Lists

  "合并k个有序链表"

Description Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Discussion 合并k个有序的链表。最直观的方法自然先合并前两个1和2,再合并12和3,再合并123和4……但是这样的话效率并不高。因为每次要比较的链表长度呈直...

[LeetCode]8. String to Integer(atoi)

  "把一个字符串输出为整数"

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

[LeetCode]7. Reverse Integer

  "求一个整数的逆序"

Description Reverse digits of an integer. The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows. Example Example1: x = 123, re...

[LeetCode]5. Longest Palindromic Substring

  "求一个字符串的最长回文子串"

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

[LeetCode]4. Median of Two Sorted Arrays

  "求两个有序数组的中指"

Description 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 should be O(log (m+n)). Example ...

[LeetCode]3. Longest Substring Without Repeating Characters

  "在一个数组中查找无重复字符的最长子串"

Description Given a string, find the length of the longest substring without repeating characters. Example Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", th...

[LeetCode]11. Container With Most Water

  "如何使一个容器的容积最大"

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

[LeetCode]10. Regular Expression Matching

  "正则表达式匹配"

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