
数据结构
文章平均质量分 65
attention!
新丰美酒斗十千,咸阳游侠多少年。相逢意气为君饮,系马高楼垂柳边。
展开
-
平衡二叉树
Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of ever...原创 2018-12-12 19:30:25 · 121 阅读 · 0 评论 -
remove duplicates from sorted array ii(从重复数组中移除重复元素)
类似问题:remove duplicates from sorted list(移除有序链表中的重复元素)题目描述Follow up for “Remove Duplicates”:What if duplicates are allowed at most twice?For example,Given sorted array A =[1,1,1,2,2,3],Your fun...原创 2019-01-10 20:16:40 · 584 阅读 · 0 评论 -
swap nodes in pairs(成对的交换链表结点)
题目描述Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only con...原创 2019-01-05 16:50:39 · 216 阅读 · 0 评论 -
remove duplicates from sorted list(移除有序链表中的重复元素)
题目描述Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.题目大...原创 2019-01-01 15:52:36 · 357 阅读 · 0 评论 -
count-and-say
题目描述The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, …1 is read off as"one 1"or11.1 1is read off as"two 1s"or21.2 1is read off as"one 2, thenon...原创 2019-01-06 20:55:53 · 219 阅读 · 0 评论 -
pascals triangle(杨辉三角、帕斯卡三角)
题目描述Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5,Return:[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]题目大意杨辉三角给定一个非负整数 numRows,生成杨辉三角的前 numRo...原创 2019-01-11 17:26:59 · 567 阅读 · 0 评论 -
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 binary tree andsu...原创 2019-01-02 19:31:45 · 206 阅读 · 0 评论 -
pascals triangle ii(杨辉三角、帕斯卡三角)
题目描述Given an index k, return the k th row of the Pascal’s triangle.For example, given k = 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?题目大意给定一个索引值k,返回杨辉...原创 2019-01-12 12:26:14 · 235 阅读 · 0 评论 -
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 right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7},...原创 2019-01-13 15:49:10 · 194 阅读 · 0 评论 -
merge-sorted-array(合并已排序的数组)
题目描述Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in...原创 2019-01-08 15:58:24 · 1254 阅读 · 0 评论 -
clone graph(克隆一个图)
题目描述Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization:Nodes are labeled uniquely.We use #as a separator for each no...原创 2019-01-14 20:38:04 · 742 阅读 · 0 评论 -
Symmetric Tree(对称树)
题目描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric:But the following is not:Note:Bonus points if you co...原创 2019-01-05 12:57:18 · 366 阅读 · 0 评论 -
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).For example:Given binary tree{3,9,20,#,#,15,7},return its level order trav...原创 2018-12-30 17:27:41 · 276 阅读 · 0 评论 -
从有序数组中移除相等的数值
题目描述Remove Duplicates From Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for anoth...原创 2018-12-19 23:05:41 · 230 阅读 · 0 评论 -
搜索一个2D矩阵
Search A 2D Matrix(搜索一个2D矩阵)Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.Th...原创 2018-12-14 16:39:58 · 276 阅读 · 0 评论 -
二叉树遍历(中序)(递归+非递归)
Binary Tree Inorder Traversal(二叉树中序遍历)Given a binary tree, return the inorder traversal of its nodes’ values.For example:Given binary tree{1,#,2,3},return[1,3,2].Note: Recursive solution is triv...原创 2018-12-14 23:06:00 · 436 阅读 · 0 评论 -
生成括号
题目Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:“((()))”, “(()())”, “(())...原创 2018-12-15 23:06:43 · 243 阅读 · 0 评论 -
二叉树遍历(前序)(递归+非递归)
题目Binary Tree Preorder TraversalGiven a binary tree, return the preorder traversal of its nodes’ values.For example:Given binary tree{1,#,2,3},return[1,2,3].Note: Recursive solution is trivia...原创 2018-12-16 14:39:20 · 251 阅读 · 0 评论 -
荷兰国旗问题(颜色排序问题)
题目描述Sort ColorsGiven 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 u...原创 2018-12-21 21:44:31 · 2208 阅读 · 0 评论 -
合并两个顺序链表
题目描述Merge Two Sorted ListsMerge 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.题目大意合并两个顺序排列的链表,并将新链表返回。新链表...原创 2018-12-17 16:14:47 · 1777 阅读 · 0 评论 -
n-queens(n皇后问题)
问题描述The n queens puzzle is the problem of placing n queens on an N x Nchessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle....原创 2018-12-28 16:03:31 · 3271 阅读 · 0 评论 -
permutations(全排列)
题目描述Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].题目大意给定一个数组集合,返回所有可能的排列。...原创 2019-01-03 16:42:27 · 5991 阅读 · 0 评论 -
n queens ii(n皇后问题-只计数不保存)
n皇后问题(保存并返回所有的解决方案)题目描述Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.题目大意著名n皇后问题。n个皇后摆放在N x N的棋盘格中,使得横、竖和两个对角线方向均不...原创 2018-12-29 23:49:43 · 385 阅读 · 0 评论 -
plus-one(加一)
题目描述Given a number represented as an array of digits, plus one to the number.题目大意用一个数组表示一个数,把这个数做加一操作。思路不需要flag!从右向左,遇到9就变0,非9就加1,然后break;digits[0]如果等于0,说明长度增加了1,则新插入一个首位,首位为1,其他位为0。代码#includ...原创 2019-01-09 11:50:28 · 397 阅读 · 0 评论