PikachuBLOG


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

16. 3Sum Closest

发表于 2017-07-03 | 分类于 LeetCode | 阅读次数
字数统计 556 | 阅读时长 3

16. 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

For example, given array S = {-1 2 1 -4}, and target = 1.
The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).

阅读全文 »

15. 3Sum

发表于 2017-07-03 | 分类于 LeetCode | 阅读次数
字数统计 1,003 | 阅读时长 5

15. 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: The solution set must not contain duplicate triplets.

1
2
3
4
5
6
For example, given array S = [-1, 0, 1, 2, -1, -4],
A solution set is:
[
[-1, 0, 1],
[-1, -1, 2]
]
阅读全文 »

14. Longest Common Prefix

发表于 2017-07-03 | 分类于 LeetCode | 阅读次数
字数统计 309 | 阅读时长 2

14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

题意:

  在一个字符串数组中查找最长相同前缀。

阅读全文 »

13. Roman to Integer

发表于 2017-07-03 | 分类于 LeetCode | 阅读次数
字数统计 932 | 阅读时长 4

13. Roman to Integer

Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.

题意:

  给定一个罗马数字,将其转换为整数,输入的数字确保在1到3999之间。

阅读全文 »

12. Integer to Roman

发表于 2017-07-03 | 分类于 LeetCode | 阅读次数
字数统计 714 | 阅读时长 3

12. Integer to Roman

Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.

题意:

  给定一个整数,将其转换为罗马数字,输入的数字确保在1到3999之间。

阅读全文 »

11. Container With Most Water

发表于 2017-06-30 | 分类于 LeetCode | 阅读次数
字数统计 445 | 阅读时长 2

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

阅读全文 »

快速排序优化

发表于 2017-06-29 | 分类于 Algorithm | 阅读次数
字数统计 2,992 | 阅读时长 13

  快速排序的思想是分治法,当每次划分时,算法若都能分成两个等长的子序列时,那么分治算法效率会达到最大。所以基准枢纽元的选择是很重要,选择基准的方式决定了分割后两个子序列的长度,进而对整个算法的效率产生决定性影响。
  通常实现的快速排序没有经过充分考虑的选择那个枢纽元,只是将第一个或最后一个元素用作枢纽元。选择第一个元素作为枢纽元的程序例子见快速排序的两种实现思路二,选择最后一个元素作为枢纽元的程序例子见快速排序的两种实现思路一

阅读全文 »

6. ZigZag Conversion

发表于 2017-06-29 | 分类于 LeetCode | 阅读次数
字数统计 926 | 阅读时长 5

6. 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(易读的))

1
2
3
P   A   H   N
A P L S I I G
Y I R
1
"PAHNAPLSIIGYIR"

And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

1
2
3
string convert(string text, int nRows);
convert("PAYPALISHIRING", 3)
"PAHNAPLSIIGYIR"
阅读全文 »

5. Longest Palindromic Substring

发表于 2017-06-28 | 分类于 LeetCode | 阅读次数
字数统计 538 | 阅读时长 3

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, and there exists one unique longest palindromic substring.

阅读全文 »

4. Median of Two Sorted Arrays

发表于 2017-06-27 | 分类于 LeetCode | 阅读次数
字数统计 1,411 | 阅读时长 7

4. Median of Two Sorted Arrays

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 1:
nums1 = [1, 3]
nums2 = [2]
The median is 2.0

Example2:
nums1 = [1, 2]
nums2 = [3, 4]
The median is(2 + 3) / 2 = 2.5

阅读全文 »
1…151617
CodePikachu

CodePikachu

技术随笔

168 日志
5 分类
7 标签
RSS
GitHub Twitter 微博 知乎
0%
© 2015 - 2020 CodePikachu
博客全站共123.3k字
本站访客数:
由 Hexo 强力驱动
主题 - NexT.Pisces