作者:zykBlog

链接:https://www.cnblogs.com/zykBlog

来源:https://www.cnblogs.com/zykBlog

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

随笔分类 -  LeetCode

摘要:class Solution { public ListNode swapPairs(ListNode head) { ListNode dummy = new ListNode(-1); ListNode p = dummy; dummy.next = head; while(p != null 阅读全文
posted @ 2020-11-09 21:08 0xcf 阅读(86) 评论(0) 推荐(0)
摘要:思路 使用队列将每个链表元素放入,每次获取最小的元素加入到链表中 实现代码 class Solution { public ListNode mergeKLists(ListNode[] lists) { Queue<ListNode> heap = new PriorityQueue<>(new 阅读全文
posted @ 2020-11-09 20:54 0xcf 阅读(83) 评论(0) 推荐(0)
摘要:class Solution { public: bool isPalindrome(int x) { if(x < 0) return false; if(x == 0) return true; vector<int>nums; while(x) nums.push_back(x % 10), 阅读全文
posted @ 2020-11-03 15:41 0xcf 阅读(33) 评论(0) 推荐(0)
摘要:class Solution { public: int myAtoi(string s) { if(s.empty()) return 0; // 去掉空格 int k = 0; while(s[k] == ' ') k++; bool flag = false; if(s[k] == '-') 阅读全文
posted @ 2020-11-03 15:39 0xcf 阅读(121) 评论(0) 推荐(0)
摘要:题目思路 翻转一个整数,主要注意溢出的判断 实现代码 class Solution { public: int reverse(int x) { if(!x) return x; int res = 0; while(x) { if(x > 0 && res > (INT_MAX - x % 10) 阅读全文
posted @ 2020-11-03 15:12 0xcf 阅读(37) 评论(0) 推荐(0)
摘要:class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int tot = nums1.size() + nums2.size(); if(tot % 2 == 阅读全文
posted @ 2020-10-25 22:22 0xcf 阅读(62) 评论(0) 推荐(0)
摘要:题目思路 双指针算法,只要没有出现重复的字符,就一直将i指针向后移动,如果出现了,就判断重复字符出现的字符是否是1次,然后j指针不断向后走 class Solution { public: int lengthOfLongestSubstring(string s) { unordered_map< 阅读全文
posted @ 2020-10-24 23:21 0xcf 阅读(61) 评论(0) 推荐(0)
摘要:题目思路 类似于大数加法的思路,只不过每次操作的时候是用链表的节点 实现代码 class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { auto dummy = new ListNode(-1), c 阅读全文
posted @ 2020-10-24 09:07 0xcf 阅读(45) 评论(0) 推荐(0)
摘要:Leetcode 1.两数之和 题目思路:使用一个哈希表,记录值和下标对应的关系,遍历整个数组,如果map中,存在target-nums[i],就得到了答案,否则就把该元素插入到map中 class Solution { public: vector<int> twoSum(vector<int>& 阅读全文
posted @ 2020-10-24 08:44 0xcf 阅读(71) 评论(0) 推荐(0)

作者:zykBlog

链接:https://www.cnblogs.com/zykBlog

来源:https://www.cnblogs.com/zykBlog

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

点击右上角即可分享
微信分享提示