数据结构
frankstar123
这个作者很懒,什么都没留下…
展开
-
leetcode 101. 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: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following原创 2016-03-16 21:47:57 · 299 阅读 · 0 评论 -
leetcode 100. Same Tree
题目内容 Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 题目分析 递归调用函原创 2016-03-15 10:25:11 · 329 阅读 · 0 评论 -
leetcode 171. Excel Sheet Column Number
题目内容 Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28原创 2016-03-15 10:09:36 · 215 阅读 · 0 评论 -
leetcode 217. Contains Duplicate
题目内容 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every eleme原创 2016-03-15 09:57:53 · 303 阅读 · 0 评论 -
leetcode 328. Odd Even Linked List
题目内容 Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it i原创 2016-03-14 23:22:18 · 210 阅读 · 0 评论 -
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. 题目分析 删除已排序链表中重复出现的结点,所有原创 2016-03-14 21:33:42 · 193 阅读 · 0 评论 -
leetcode 70. Climbing Stairs
题目内容 You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 题目分析 我们假设,最后一步完成爬台阶。那么就有两种爬法出原创 2016-03-14 21:11:48 · 234 阅读 · 0 评论 -
leetcode 242. Valid Anagram
题目内容 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 may assume原创 2016-03-14 17:14:06 · 185 阅读 · 0 评论 -
leetcode 237. 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 val原创 2016-03-14 16:49:15 · 304 阅读 · 0 评论 -
leetcode 226. Invert Binary Tree
题目描述 Invert a binary tree. 题目分析 将二叉树翻转,通过不断递归实现二叉树的翻转。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNo原创 2016-03-14 16:35:35 · 261 阅读 · 0 评论 -
leetcode 232. Implement Queue using Stacks
题目内容 Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. e原创 2016-03-14 16:21:17 · 303 阅读 · 0 评论 -
leetcode 263. Ugly Number
题目内容 Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc原创 2016-03-14 15:43:01 · 246 阅读 · 0 评论 -
leetcode 283. Move Zeroes
题目内容 Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2016-03-14 11:48:17 · 213 阅读 · 0 评论 -
leetcode 206. Reverse Linked List
题目内容 Reverse a singly linked list.题目分析 对单链表进行反转 单链表翻转的时候,搞懂结点的赋值与更新就OK了,这块有点儿绕。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListN原创 2016-03-14 11:33:47 · 230 阅读 · 0 评论 -
求二叉树的宽度
题目描述 给出一棵二叉树,求二叉树的宽度。 解析 二叉树的宽度:空的二叉树的宽度为0,非空二叉树的宽度为各层结点个数的最大值。 依然用BFS。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode rig原创 2016-03-14 09:31:52 · 553 阅读 · 0 评论 -
leetcode 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.题目解析 求一个二叉树的树的深度。 有两种求法,深度优先(DFS)和广度优先(BF原创 2016-03-12 20:40:05 · 230 阅读 · 0 评论 -
单链表中环的检测
单链表中环的检测首先设置两个指针,分别命名为fast和slow,fast指针每次向后移2步,slow指针每次向后移1步。 如果,fast指针最后走到尾结点,则没有环。 如果,fast指针和slow指针相遇,则证明有环。 环的起始结点的查询当fast与slow相遇之后, fast指针从头结点开始走,每次走1步 当fast再次与slow相遇以后,相遇处的结点为环的入口结点 证明推导1:fast指针的步长原创 2016-03-11 16:33:30 · 1728 阅读 · 0 评论 -
二叉树的前序遍历,中序遍历,后序遍历代码
前序遍历/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution原创 2016-05-30 23:26:42 · 804 阅读 · 0 评论