![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
qsope
这个作者很懒,什么都没留下…
展开
-
leetcode Algorithms 1. Two Sum
题意:简单的找nums[i]+nums[j]==target思路:标记,set,O(nlogn) 暴力 O(n*n)class Solution {public: vector twoSum(vector& nums, int target) { multisets; vectorans; for(int i原创 2017-06-06 10:39:21 · 137 阅读 · 0 评论 -
leetcode Algorithms 9. Palindrome Number
题意:判断是否回文class Solution {public: bool isPalindrome(int x) { if(x<0)return 0; int ans=0,num=x; while(x) { ans=ans*10+x%10; x/=10;原创 2017-06-15 15:41:23 · 170 阅读 · 0 评论 -
leetcode Algorithms 8. String to Integer (atoi)
题意:将一个字符串转成整形class Solution {public: int myAtoi(string str) { long long ans=0; int s=0,flag=1; while(str[s]==' ')s++; if(str[s]=='+'||str[s]=='-') fl原创 2017-06-15 15:39:33 · 205 阅读 · 0 评论 -
leetcode Algorithms 7. Reverse Integer
题意:翻转一个整数,越界返回0;思路:模拟;class Solution {public: int reverse(int x) { long long ans=0; while(x) { int z=x%10; ans=ans*10+z; x/=10;原创 2017-06-15 15:37:04 · 142 阅读 · 0 评论 -
leetcode Algorithms 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原创 2017-06-15 15:32:25 · 218 阅读 · 0 评论 -
leetcode Algorithms 5. Longest Palindromic Substring
题意:找最长回文串;思路:马拉车算法;class Solution{public: string s; char str[2010]; int p[2010]; void manacher(string s,int l) { int i,j,k,ans=0; for(i=1,j=0; i<=l; ++i,j++)s原创 2017-06-15 15:12:58 · 169 阅读 · 0 评论 -
leetcode Algorithms 4 Median of Two Sorted Arrays
题意:给你两个数组,求中位数思路:1.最基础的思路,类似归并排序,将两个数组的合并成一个有序的数组,找第k小;复杂度(O(n+m)) 2.二分数组找第k小,然后去另外一个数组找比其小的个数,判断是否第k小,复杂度O(log(n)*log(m)); 3.自己想的类似第二个思路,既然你已经二分第一个数组,假设二分的位置为pos,你知道你要找第k小原创 2017-06-15 14:43:32 · 231 阅读 · 0 评论 -
leetcode Algorithms 3. Longest Substring Without Repeating Characters
题意:最长连续子串,并且字串中没有重复的字符思路:吊吊的O(n)算法--尺取法;class Solution {public: int flag[300]; int lengthOfLongestSubstring(string s) { int x=s.size(); int st=0,en=0; memset(flag,原创 2017-06-06 10:54:35 · 176 阅读 · 0 评论 -
leetcode Algorithms 2. Add Two Numbers
题意:数的加法,因为数是翻转的,往后进位即可思路:模拟,链表的过程,原来都是数组写,指针的写不习惯。。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL)原创 2017-06-06 10:47:45 · 171 阅读 · 0 评论 -
LeetCode 206. Reverse Linked List 翻转一个链表
记录前一个,中间一个,后一个。class Solution {public: ListNode* reverseList(ListNode* head) { if(head==NULL)return head; ListNode *elem; elem=head; head=head->next; elem->...原创 2018-03-01 21:53:25 · 132 阅读 · 0 评论