LeetCode
文章平均质量分 87
ACLJW
这个作者很懒,什么都没留下…
展开
-
1. Two Sum
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 exactly one solution, and you may not use the same el...原创 2018-03-10 08:13:49 · 130 阅读 · 0 评论 -
16. 3Sum Closest
16. 3Sum Closest和之前3Sum那道题思路一样,刚开始想的是不用每次计算误差,只需要在小于目标和大于目标的转折点出计算两次然后临界的时候计算一次即可,可是实际上和每次都计算误差速度一样的。。。class Solution {public: int threeSumClosest(vector<int>& nums, int target) {...原创 2018-09-24 17:20:36 · 136 阅读 · 0 评论 -
15. 3Sum
15. 3Sumclass Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(),nums.end()); vector<vector<int>> res; ...原创 2018-09-08 23:57:19 · 115 阅读 · 0 评论 -
11. Container With Most Water
11. Container With Most Water设置两个指针i j ,分别指向首尾两块板,然后向中间移动,那么宽度变小的情况下为了增大面积只有让高度变大,所以每次移动所指板较低的指针,然后计算面积,重复以上过程。int max(int a,int b){ return a > b ? a : b;}int maxArea(int* height, int he...原创 2018-08-27 12:30:35 · 124 阅读 · 0 评论 -
14. Longest Common Prefix
14. Longest Common Prefixchar s[100000];int min(int a,int b){ return a < b ? a : b;}char* longestCommonPrefix(char** strs, int strsSize) { int len = 10000,cnt = 0; for(int i = 0;i...原创 2018-08-26 23:47:05 · 125 阅读 · 0 评论 -
12. Integer to Roman
12. Integer to Romanchar s[100];char* intToRoman(int num) { char rs[] = "MDCLXVI"; int ts[] = { 1000,500,100,50,10,5,1 }; int cnt = 0; while(num){ int i = 0; while(...原创 2018-08-26 23:32:36 · 130 阅读 · 0 评论 -
13. Roman to Integer
13. Roman to Integerint romanToInt(char* s) { int dic[26]; dic['I'-'A'] = 1; dic['V'-'A'] = 5; dic['X'-'A'] = 10; dic['L'-'A'] = 50; dic['C'-'A'] = 100; dic['D'-'A'] = ...原创 2018-08-26 22:32:08 · 395 阅读 · 0 评论 -
7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envi...原创 2018-03-28 18:05:49 · 96 阅读 · 0 评论 -
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)P A H NA P L S I I G...原创 2018-03-28 16:53:11 · 115 阅读 · 0 评论 -
10. Regular Expression Matching
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 stri...原创 2018-03-30 21:56:59 · 110 阅读 · 0 评论 -
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.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer. Example:I...原创 2018-03-25 12:36:18 · 163 阅读 · 0 评论 -
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...原创 2018-03-24 18:13:02 · 120 阅读 · 0 评论 -
9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the intege...原创 2018-03-29 23:02:43 · 85 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...原创 2018-03-12 08:33:45 · 121 阅读 · 0 评论 -
2. Add Two Numbers
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 contain a single digit. Add the two numbers and return原创 2018-03-11 20:05:45 · 115 阅读 · 0 评论 -
8. String to Integer (atoi)
8. String to Integer (atoi)class Solution {public: int myAtoi(string str) { int Max = (1<<31)-1, Min = -1<<31; int i = 0; int minus = 1; while(str[i...原创 2018-09-20 21:06:56 · 128 阅读 · 0 评论