- 博客(111)
- 资源 (1)
- 收藏
- 关注
原创 LeetCode 20. Valid Parentheses 辅助数据结构栈
Valid Parentheses题意注意思路代码结果20. Valid Parentheses Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must clo
2017-05-24 11:34:25 380
原创 LeetCode 150. Evaluate Reverse Polish Notation 辅助数据结构栈
题目题意注意思路代码结果题目 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some exa
2017-05-24 11:17:12 324
原创 LeetCode 19. Remove Nth Node From End of List 对撞指针
Remove Nth Node From End of List题目题意注意思路代码结果Delete Node in a Linked List题目题意注意思路代码结果19.Remove Nth Node From End of List题目 Given a linked list, remove the nth node from the end of list an
2017-05-23 17:38:21 356
原创 LeetCode 24. Swap Nodes in Pairs ***** 双节点交换
题目题意注意思路代码结果题目 Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should
2017-05-23 16:34:15 226
原创 LeetCode 82. Remove Duplicates from Sorted List II pre指针,首元素的处理
题目题意注意思路代码结果题目 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, ret
2017-05-23 15:31:04 335
原创 LeetCode 203. Remove Linked List Elements *****虚拟头结点
题目题意注意思路代码结果题目 Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5 题意 给定一个
2017-05-22 15:00:19 536
原创 LeetCode 2. Add Two Numbers ***** 进位的巧妙解决
题目 You 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 numbers and retu
2017-05-22 10:47:41 446
原创 LeetCode 83. Remove Duplicates from Sorted List ***
题目题意注意思路代码题目 Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.
2017-05-20 22:32:52 234
原创 LeetCode 92. Reverse Linked List II ***** 虚拟头结点
题目题意注意思路代码题目 Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Not
2017-05-20 22:01:01 285
原创 LeetCode 206. Reverse Linked List *****三指针 (pre,cur,next)
题目题意注意思路题目 Reverse a singly linked list.题意 反转一个单链表 e.g: 1->2->3->4->5->NULL NULL<-1<-2<-3<-4<-5注意 链表的题目一般不允许修改链表内的内容,只能修改指向思路 需要三个指针,分别保存之前,当前,之后的信息。 1.更改cur的next指向 2.之后pre
2017-05-20 21:40:23 1207
原创 LeetCode 220. Contains Duplicate III *****理解条件,查找表
题目题意注意思路代码结果题目 Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the
2017-05-18 11:15:42 443
原创 LeetCode 219. Contains Duplicate II ***** 滑动窗口,查找表 217.Contains Duplicate
219题目题意注意思路代码结果217Contains Duplicate 题目题意思路代码结果219题目 Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nu
2017-05-18 10:51:51 356
原创 LeetCode 149. Max Points on a Line **** 灵活键,查找表
题目题意注意思路代码结果题目 Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Subscribe to see which companies asked this question.题意 在一个2D平面内有n个点,找到
2017-05-17 14:53:25 223
原创 LeetCode 447. Number of Boomerangs ***** 灵活键,查找表
题目题意注意思路代码结果题目 Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k
2017-05-16 20:56:52 464
原创 LeetCode 49. Group Anagrams ***** multiset
题目题意注意我的思路实现不好代码结果参考思路实现multiset代码结果题目 Given an array of strings, group anagrams together. For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return: [ [“ate”,
2017-05-16 15:41:07 262
原创 LeetCode 454. 4Sum II ***** 灵活的设定键
题目题意注意思路代码结果区别于184Sum题目 Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit eas
2017-05-16 14:29:39 412
原创 LeectCode 16. 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 exa
2017-05-16 11:30:28 232
原创 LeetCode 15.3Sum 18.4Sum 对撞指针 ****
题目 15-3Sum题意注意思路代码结果题目 18-4Sum题意注意思路代码结果题目 15-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 give
2017-05-11 22:10:48 502
原创 LeetCode 1.Two Sum map 初次使用Markdown*****
外传 经过室友推荐blog转战Markdown编辑,初次使用还觉得挺不方便需要那么多快捷键,不如鼠标点的快。今天这一篇文章才写一半就觉得很好用,就像电脑操作用鼠标点击和windows快捷键操作一样爽,在此向还没转战的朋友推荐,顺便练习自己的操作。 不方便的是代码高亮显示不好。 参考快速上手 记录插入链接格式 题目题意注意思路1代码
2017-05-10 14:44:09 1007
原创 C++组合和继承 组合中会涉及到默认构造函数和拷贝构造函数的问题
背景 上午师弟让我看一下他遇到的问题,让我意识到组合问题理解的还不是很清晰,顺便把他的代码记录下来。 在speed类中需要使用wheel的一个对象,需要对wheel初始化,在speed的构造函数里使用了赋值初始化,所以在wheel中需要定义一个默认构造函数。第一眼看下边的代码觉得没问题,编译老是链接器错误在speed构造函数里,之后改为对象指针解决。后边慢慢看了一
2017-05-09 19:38:46 719
原创 LeetCode 451. Sort Characters By Frequency ***** map按值排序转vector,优先队列,频率当下标
一、题目Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.
2017-05-08 21:49:13 539
原创 LeetCode 205. Isomorphic Strings 双map ***
一、题目Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to gett.All occurrences of a character must be replaced with
2017-05-08 21:28:53 344
原创 LeetCode 290. Word Pattern 双map *****
一、题目Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter inpattern and a non-empty word in str
2017-05-07 15:30:26 306
原创 LeetCode 202. Happy Number
一、题目Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the s
2017-05-05 21:03:39 280
原创 LeetCode 242. Valid Anagram (map使用)
一、题目Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You m
2017-05-05 20:50:32 366
原创 LeetCode 349. Intersection of Two Arrays 350. Intersection of Two Arrays II set map使用 ****
之前LeetCode的题主要是对数字,字符串处理,从今天开始做一些查找方面的题。同时需要熟练掌握C++标准库STL为我们提供的容器,算法,主要是map,set,unordered_set,unordered_map的使用。两道题都挺简单,放在一块来写。一、第一题题目Given two arrays, write a function to compute their intersect
2017-05-04 21:40:20 328
原创 LeetCode 76. Minimum Window Substring 滑动窗口 *****
一、题目Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is
2017-05-04 17:12:17 637
原创 LeetCode 438. Find All Anagrams in a String 滑动窗口
一、题目Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the length of both stringss and p will
2017-05-03 19:52:30 446
原创 LeetCode 3. Longest Substring Without Repeating Characters 滑动窗口
一、题目Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "
2017-05-03 16:11:11 508
原创 LeetCode 209. Minimum Size Subarray Sum 滑动窗口
一、题目Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥s. If there isn't one, return 0 instead.For example, gi
2017-05-03 11:50:16 642
原创 LeetCode 11. 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,
2017-05-02 19:19:07 506 1
原创 LeetCode 345. Reverse Vowels of a String 对撞指针
一、题意Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".No
2017-05-02 16:01:36 365
原创 LeetCode 344. Reverse String 对撞指针
一、题目Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".题意:给定一个字符串,反转输出。类似的对撞指针的方法。class Solution {public: string
2017-05-02 15:11:35 684
原创 LeetCode 125. Valid Palindrome 对撞指针(双索引)
一、题目Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is
2017-05-01 19:57:14 657
原创 LeetCode 167. Two Sum II - Input array is sorted (双索引技术对撞指针)
一.题目:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two
2017-05-01 18:32:32 437
原创 LeetCode 215 Kth Largest Element in an Array 含有各种快排对比
题目:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.
2017-04-19 15:36:34 619
原创 LeetCode 88. Merge Sorted Array 归并的过程
Given two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.题意:对于有序的两个数组nums1,nums2进行归并到nums1里保持其有序性1.按照归并排序进行归并的过程,需要单独开辟一块空间O(n),时间复杂度O(n)2.在进行归并的过程,需要注意越界
2017-03-14 19:48:37 481
原创 LeetCode 75. Sort Colors (三路快排)
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0,
2017-03-14 16:45:50 560
原创 LeetCode 80. Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five e
2017-03-14 11:23:16 300
原创 LeetCode 26 remove Duplicate 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 in place with
2017-03-12 17:12:36 318
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人