自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(44)
  • 资源 (1)
  • 收藏
  • 关注

原创 LeetCode 404. Sum of Left Leaves 递归终止条件

404. Sum of Left Leaves Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree,

2017-05-31 21:46:57 261

原创 LeetCode 112. Path Sum 注意递归的终止条件

112. Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below b

2017-05-31 21:21:09 465

原创 LeetCode 226. Invert Binary Tree 递归、指针交换 思考链表的交换

226. Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1Trivia: This problem was i

2017-05-31 14:53:15 270

原创 LeetCode 104. Maximum Depth of Binary Tree和111. Minimum Depth of Binary Tree 递归

104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

2017-05-27 19:34:51 447

原创 LeetCode 347. Top K Frequent Elements 优先队列的使用及注意事项

Top K Frequent Elements题意注意思路代码结果优先队列的使用347. Top K Frequent Elements Given a non-empty array of integers, return the k most frequent elements. For example, Given [1,1,1,2,2,3] and k = 2

2017-05-26 17:38:10 666

原创 LeetCode 279. Perfect Squares 转换思维图的无权BFS,寻最短路径

Perfect Squares题意注意思路代码题外memset的使用279. Perfect Squares Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n. For example:

2017-05-26 17:15:34 799

原创 LeetCode 107. Binary Tree Level Order Traversal II 树的BFS、DFS

Binary Tree Level Order Traversal II题意思路代码BFSDFS107. Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to

2017-05-25 22:28:00 697

原创 LeetCode 102. Binary Tree Level Order Traversal 树的广度优先遍历 辅助数据结构队列

Binary Tree Level Order Traversal题意思路代码结果102. Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level

2017-05-25 22:15:36 627

原创 LeetCode 94. Binary Tree Inorder Traversal 树的前序、中序,后序遍历的非递归实现

题目Binary Tree Inorder TraversalBinary Tree Preorder TraversalBinary Tree Postorder Traversal思路代码题目94. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes

2017-05-24 20:05:01 298

原创 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 366

原创 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 304

原创 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 346

原创 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 219

原创 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 328

原创 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 492

原创 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 436

原创 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 223

原创 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 276

原创 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 1140

原创 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 424

原创 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 313

原创 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 210

原创 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 422

原创 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 247

原创 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 362

原创 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 217

原创 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 459

原创 LeetCode 1.Two Sum map 初次使用Markdown*****

外传 经过室友推荐blog转战Markdown编辑,初次使用还觉得挺不方便需要那么多快捷键,不如鼠标点的快。今天这一篇文章才写一半就觉得很好用,就像电脑操作用鼠标点击和windows快捷键操作一样爽,在此向还没转战的朋友推荐,顺便练习自己的操作。 不方便的是代码高亮显示不好。 参考快速上手 记录插入链接格式 题目题意注意思路1代码

2017-05-10 14:44:09 968

原创 C++组合和继承 组合中会涉及到默认构造函数和拷贝构造函数的问题

背景    上午师弟让我看一下他遇到的问题,让我意识到组合问题理解的还不是很清晰,顺便把他的代码记录下来。       在speed类中需要使用wheel的一个对象,需要对wheel初始化,在speed的构造函数里使用了赋值初始化,所以在wheel中需要定义一个默认构造函数。第一眼看下边的代码觉得没问题,编译老是链接器错误在speed构造函数里,之后改为对象指针解决。后边慢慢看了一

2017-05-09 19:38:46 695

原创 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 523

原创 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 330

原创 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 293

原创 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 266

原创 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 352

原创 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 312

原创 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 602

原创 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 436

原创 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 470

原创 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 594

原创 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 497 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除