![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
处级干部
这个作者很懒,什么都没留下…
展开
-
38. 外观数列
class Solution {public: string countAndSay(int n) { if(n==1){ return "1"; } string str=countAndSay(n-1);//递归把之前的那个数组搞出来 //之后用计数器,相等就加加然后改字符串!!!有了之前的字符串应该好做了吧 string res=""; int count=1; .原创 2020-07-04 16:56:27 · 126 阅读 · 0 评论 -
35. 搜索插入位置 && 二分查找法
1.暴力搜索就完事class Solution {public: int searchInsert(vector<int>& nums, int target) { for(int i=0;i<nums.size();i++){ if(target<=nums[i]){ return i; } } return nums.size();.原创 2020-07-01 12:12:04 · 148 阅读 · 0 评论 -
28. 实现 strStr() && KMP算法
class Solution {public: int strStr(string haystack, string needle) { if(needle=="") return 0; int needle_len=needle.size(); int next[needle_len]; next[0]=0; int len=0; int i=0,j=0; f.原创 2020-07-01 09:10:56 · 124 阅读 · 0 评论 -
26. 删除排序数组中的重复项 27. 移除元素
class Solution {public: int removeDuplicates(vector<int>& nums) { for(int i=1;i<nums.size();){ if(nums[i]==nums[i-1]){ nums.erase(nums.begin()+i); } else i++; .原创 2020-06-27 21:01:08 · 91 阅读 · 0 评论 -
20. 有效的括号
#include<stack>class Solution {public: bool isValid(string s) { stack<char> str; char top='0'; for(int i=0;i<s.size();i++){ str.push(s[i]); if(s[i]==')'&&top=='('){ .原创 2020-06-21 14:15:54 · 84 阅读 · 0 评论 -
160. 相交链表
编写一个程序,找到两个单链表相交的起始节点。如下面的两个链表:在节点 c1 开始相交。 示例 1:输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3输出:Reference of the node with value = 8输入解释:相交节点的值为 8 (注意,如果两个链表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B原创 2020-05-17 17:58:54 · 107 阅读 · 0 评论 -
141. 环形链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCycle(ListNode *head) { ListNode *fast = new ListNod原创 2020-05-16 11:23:05 · 126 阅读 · 0 评论 -
Leetcode 删除排序链表中的重复元素
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* deleteDuplicates(ListNode* head) { ListNode *p=hea原创 2020-05-14 22:00:36 · 119 阅读 · 0 评论 -
Leetcode 9.回文数 反转一半数字
方法:反转一半数字思路映入脑海的第一个想法是将数字转换为字符串,并检查字符串是否为回文。但是,这需要额外的非常量空间来创建问题描述中所不允许的字符串。第二个想法是将数字本身反转,然后将反转后的数字与原始数字进行比较,如果它们是相同的,那么这个数字就是回文。但是,如果反转后的数字大于 \text{int.MAX}int.MAX,我们将遇到整数溢出问题。按照第二个想法,为了避免数字反转可能导...原创 2020-05-14 22:01:02 · 167 阅读 · 0 评论 -
LeetCode 1
LeetCode 1 两数之和两遍哈希class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int,int> m; for(int i=0;i<nums.size();i...原创 2020-05-14 22:01:15 · 135 阅读 · 0 评论 -
Leetcode 2
给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。您可以假设除了数字 0 之外,这两个数都不会以 0 开头。示例:输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)输出:7 -> 0 ->...原创 2020-05-14 22:01:32 · 84 阅读 · 0 评论 -
LeetCode 7. 整数反转
class Solution {public: int reverse(int x) { if(x>2147483648-1||x<-2147483648){ return 0; } long int temp=10; long int n=x; long int sum=...原创 2020-05-14 22:01:45 · 84 阅读 · 0 评论