leetcode
lennonmwy
这个作者很懒,什么都没留下…
展开
-
leetcode160. Intersection of Two Linked Lists
CSDN博客作为leetcode刷题笔记,以后有机会会补上机器学习的内容和之前kaggle比赛的代码。这道题有两种解法。第一种是算出两条链表的长度的差值。用比较长的链表移位差值大小,就可以一一比较了。c++,解法一:/** * Definition for singly-linked list. * struct ListNode { * int val; * ...原创 2018-09-04 15:42:22 · 86 阅读 · 0 评论 -
leetcode 4. Median of Two Sorted Arrays
http://windliang.cc/2018/07/18/leetCode-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...原创 2018-10-10 10:42:24 · 166 阅读 · 0 评论 -
leetcode 690. Employee Importance
You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id.For example, employee 1 is the leader of employe...原创 2018-09-26 18:07:46 · 102 阅读 · 0 评论 -
leetcode 204. Count Primes
这道题是easy标签的,我的做法效率比较低,涉及到一种经典的找素数的方法,在这里记录一下。问题一:求前n个数里有几个素数。解法一:经典算法(埃拉托斯特尼筛法)class Solution {public: int countPrimes(int n) { vector <bool> isprime(n,true); for (int i = 2;...原创 2018-09-26 11:22:06 · 85 阅读 · 0 评论 -
leetocde 24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only...原创 2018-09-25 21:37:12 · 70 阅读 · 0 评论 -
leetcode 19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, t...原创 2018-09-25 20:58:07 · 74 阅读 · 0 评论 -
leetcode 445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return i...原创 2018-09-25 19:11:15 · 78 阅读 · 0 评论 -
leetcode 109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the ...原创 2018-09-25 16:44:50 · 97 阅读 · 0 评论 -
leetcode 2. Add Two Numbers
2.Add Two NumbersYou 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...原创 2018-09-25 11:36:50 · 99 阅读 · 0 评论 -
leetcode 876. Middle of the Linked List
Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.这道题,比较简单,记录链表中间的值,不过还是记录一下快慢指针的做法。先是我的...原创 2018-09-05 10:10:39 · 112 阅读 · 0 评论 -
leetcode 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time a...原创 2018-09-04 21:31:04 · 79 阅读 · 0 评论 -
leetcode 206. Reverse Linked List
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL这道题没有做出来,递归还是得多多练习才能掌握。第一种方法,递归做法。/** * Definition for singly-link...原创 2018-09-04 19:55:49 · 72 阅读 · 0 评论 -
leetcode 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5这道题属于easy,但我做的也不是很快。我的做法...原创 2018-09-04 16:27:37 · 71 阅读 · 0 评论 -
leetcode 55. Jump Game
class Solution {public: bool canJump(vector<int>& nums) { int i = 0,n = nums.size() -1; for(int reach = 0;i<=n && i<=reach;i++) reach = max(i+n...原创 2018-10-10 14:55:04 · 88 阅读 · 0 评论