关闭

103. Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary ...
阅读(15) 评论(0)

107. 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,null,null,15,...
阅读(17) 评论(0)

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). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 ...
阅读(18) 评论(0)

145. Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. 题意是要求二叉树的后序遍历,那...
阅读(10) 评论(0)

94. 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 / 3 return [1,3,2]. 题意是对二叉树进行中序遍历,...
阅读(21) 评论(0)

144. Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3]. 题意是要先序遍历一个二叉树...
阅读(59) 评论(0)

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 examples: ["2", "1", ...
阅读(23) 评论(0)

84. Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width o...
阅读(16) 评论(0)

5. Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. ...
阅读(29) 评论(0)

数据结构之:二叉树

今天复习到了二叉树,首先是了解一下二叉树的一下定义: 二叉树是每个节点最多有两个子树的树结构,通常称为左/右子树。如图所示: 其中深度Depth可以理解为层数,那么第i层则有2^(i-1)那么多的节点。其中没有左右子树的节点称为叶节点,而 其他的称为根节点。例如值为8~15的节点就是叶子节点。 而树的类型也有很多种,其中基本的有: 1.完全二叉树——假如一棵树的最大深度为D,那么1到...
阅读(50) 评论(0)

数据结构之:字符串

一、简介 字符串或者说串(String)是由数字、字母。下划线组成的一串字符。一般可以记为s="a0a1a2a3...an" (n>=0并且n是有限非负整数)。 从数据结构上来看,用c++来说,字符串是一种特殊的线性表,也就是里面的每个元素都是字符的一种线性表。可以是用数组实现,或者链表实现。具体的优缺点可以参照数组和链表的优缺点。 二、c++中的字符串string 而在c++中的stri...
阅读(51) 评论(0)

数据结构之:栈与队列

最近在复习数据结构与算法,加上刚开始写博客,所以打算把复习的东西在博客上记录,这样也是方便以后的查看。 一、栈 说起栈,栈是一种后进先出(Last In First Out)的数据结构,简称LIFO。主要的操作是进站push和出栈pop(也叫压栈)。栈主要是在序列的一头进行操作: 所以一直觉得这是一个比较流氓的行为,怎么先排队的轮到后面才到它啊。但是流氓的地方正是它魅力的地方,栈得的...
阅读(77) 评论(0)

8. String to Integer (atoi)

Problem: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possi...
阅读(49) 评论(0)

125. Valid Palindrome

Problem: 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 ...
阅读(46) 评论(0)

24. Swap Nodes in Pairs

Problem: 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 use only constan...
阅读(40) 评论(0)

61. Rotate List

Problem: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 由题意得,给出一个链表和一个K...
阅读(42) 评论(0)

86. Partition List

Problem: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the no...
阅读(43) 评论(0)

92. Reverse Linked List II

Problem: 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. Note: Given m,...
阅读(30) 评论(0)

206. Reverse Linked List

Problem: Reverse a singly linked list. 题目就一行,翻转一个链表。所以题目也是比较简单,我用了递归的方法实现。 Code:(LeetCode运行6ms) /** * Definition for singly-linked list. * struct ListNode { * int val; * List...
阅读(45) 评论(0)

2. Add Two Numbers

Problem: 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 number...
阅读(58) 评论(0)
59条 共3页1 2 3 下一页 尾页
    个人资料
    • 访问:2690次
    • 积分:595
    • 等级:
    • 排名:千里之外
    • 原创:59篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档