leetcode,c++
Barbie_1229
朝着C++ Programmer努力
展开
-
Leetcode160. Intersection of Two Linked Lists/C++
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists: A: a1 → a2 ↘原创 2017-12-20 16:56:26 · 173 阅读 · 0 评论 -
Leetcode11. Container With Most Water
Given n non-negative integers a1, a2, ...,an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of linei is at (i, ai) and (i, 0). Find原创 2018-01-26 15:30:33 · 127 阅读 · 0 评论 -
Leetcode15. 3Sum
Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain du原创 2018-01-26 16:09:21 · 150 阅读 · 0 评论 -
Leetcode16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2018-01-26 18:08:20 · 142 阅读 · 0 评论 -
Leetcode18. 4Sum
Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution s原创 2018-01-26 18:27:57 · 199 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in-place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this by modifying原创 2018-01-26 18:49:51 · 141 阅读 · 0 评论 -
Leetcode27. Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array原创 2018-01-26 18:56:59 · 159 阅读 · 0 评论 -
Leetcode35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2018-01-28 22:10:43 · 152 阅读 · 0 评论 -
Leetcode1.Two Sum
又回来刷题了,小一个月被各种事情耽误没有写代码,再写的时候完全手生。接下来的时间要全身心准备年后的各种内推,希望3月能去一个好公司实习。无他,唯手熟尔。这题还是挺简单的,我第一反应就是用双循环,不过确实时间效率并不高,看了一下百度上的各种答案,有的用双指针和map的hash,没太详细看,慢慢来,毕竟这种简单题命中率并不高Given an array of integers, r原创 2018-01-25 15:04:29 · 167 阅读 · 0 评论 -
Leetcode95. Unique Binary Search Trees II
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1原创 2018-01-31 14:40:37 · 275 阅读 · 0 评论 -
Leetcode96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2018-01-31 11:16:23 · 212 阅读 · 0 评论 -
Leetcode206. Reverse Linked List
Reverse a singly linked list.反转链表的题目,很简单,和之前刷的lintcode题目一致,还是决定刷leetcode吧,一是因为最近网速算是给力,二是锻炼一下英语能力。#includeusing namespace std;struct ListNode {int val;ListNode *next;ListNode(int x) : val(x),原创 2017-12-21 15:38:59 · 136 阅读 · 0 评论 -
Leetcode234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?判断链表是否是回文,第一想法是遍历一次通过相加的方式得到sum,然后同时逆置链表,之后再相加得到temp,看是否相等。代码如下:class So原创 2017-12-21 16:15:28 · 123 阅读 · 0 评论 -
Leetcode141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 判断链表是否有环问题,用快慢指针解决。如果有环,快指针和满指针一定会相遇,并且是在慢指针走完一圈之前,或者刚好走完一圈。class Solution {pu原创 2017-12-21 17:14:35 · 113 阅读 · 0 评论 -
Leetcode203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5 在链表中删除值为6的节点。这题调了好久,看原创 2017-12-21 19:59:18 · 122 阅读 · 0 评论 -
Leetcode237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-12-21 20:15:18 · 153 阅读 · 0 评论 -
Leetcode21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example: Input: 1->2->4, 1->3->4Output: 1->1->2->3->4-原创 2017-12-21 22:55:50 · 167 阅读 · 0 评论 -
19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the l原创 2017-12-22 17:03:18 · 144 阅读 · 0 评论 -
Leetcode94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2]. 非常简单的中序遍历,都AC以后才弄明白说可不可以用迭代原创 2018-01-30 18:41:34 · 190 阅读 · 0 评论 -
Leetcode31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o原创 2018-01-29 16:30:02 · 146 阅读 · 0 评论