自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(68)
  • 收藏
  • 关注

原创 235. Lowest Common Ancestor of a Binary Search Tree | 二叉查找树两个节点的最低共同祖先

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw

2017-05-03 21:15:54 358 1

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

2017-05-02 15:13:02 331

原创 199. Binary Tree Right Side View | 从右边看二叉树得到的集合

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1

2017-04-19 16:25:26 360

原创 230. Kth Smallest Element in a BST | 二叉排序树中查找第K小的数

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ? k ? BST's total elements.Follow up:What if the

2017-04-18 21:48:34 686 1

原创 222. Count Complete Tree Nodes | 完全二叉树的节点数

Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,

2017-04-16 20:29:06 406

原创 129. Sum Root to Leaf Numbers | 二叉树整数和

Total Accepted: 105665Total Submissions: 295189Difficulty: MediumContributor: LeetCodeGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.A

2017-04-15 20:45:33 317

原创 257. Binary Tree Paths | 二叉树的路径

Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]Cre

2017-04-14 20:04:49 767

原创 538. Convert BST to Greater Tree | 二叉排序树转换成Greater树

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Exam

2017-04-14 15:01:53 446

原创 543. Diameter of Binary Tree | 二叉树的“直径”

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may n

2017-04-14 14:31:10 973

原创 318. Maximum Product of Word Lengths | 字符串长度相乘最大值

Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le

2017-04-08 20:27:46 389

原创 477. Total Hamming Distance | 整数间数的二进制中不同的位数

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance between all pairs of the giv

2017-03-24 16:26:04 288

原创 445. Add Two Numbers II | 链表的整数相加

Total Accepted: 15900Total Submissions: 34368Difficulty: MediumContributors: AdminYou are given two non-empty linked lists representing two non-negative integers. The most significant digit co

2017-03-24 15:40:27 322

原创 508. Most Frequent Subtree Sum | 查找子树和中出现次数最多的和

Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (includi

2017-03-15 16:22:55 657

原创 Find Bottom Left Tree Value |找到二叉树最后一层的最左边的节点的值

Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3

2017-03-11 15:05:45 2796

原创 234. Palindrome Linked List | 判断一个单链表是否是回文

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Subscribe to see which companies asked this question.思路:获得链表的长度,逆置

2017-03-08 15:59:27 272

原创 205. Isomorphic Strings | 判断两个字符串形式是否相同

Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot

2017-03-02 14:44:52 331

原创 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 binary tree and sum

2017-03-02 11:12:10 319

原创 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.empty(

2017-02-27 20:09:17 226

原创 141. Linked List Cycle | 判断单链表是否有环

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Subscribe to see which companies asked this question.思路:用两个遍历指针,一个每次前进一步

2017-02-26 19:26:27 323

原创 110. Balanced Binary Tree | 判断是否是平衡二叉树

Given 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 every node never diffe

2017-02-26 15:12:53 406

原创 434. Number of Segments in a String | 判断字符串中单词的数量

Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain any non-printable characters.

2017-02-25 21:24:02 430

原创 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 [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3

2017-02-24 16:05:27 264

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

2017-02-24 11:17:07 221

原创 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".Note

2017-02-23 16:53:16 607

原创 367. Valid Perfect Square |计算一个数是否是一个数的平方

Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return

2017-02-23 16:33:09 431

原创 235. Lowest Common Ancestor of a Binary Search Tree | 二叉搜索树任意两点的最低共同父节点

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw

2017-02-23 15:38:58 276

原创 108. Convert Sorted Array to Binary Search Tree | 有序数组生成平衡二叉搜索树

Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode

2017-02-23 10:56:36 263

原创 21. Merge Two Sorted Lists | 连接两个有序单链表

Merge 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./** * Definition for singly-linked list. * public cla

2017-02-23 10:39:07 262

原创 419. Battleships in a Board | 计算战船的数量

Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with'.'s. You may assume the following rules:You receive a valid b

2017-02-21 20:54:14 249

原创 459. Repeated Substring Pattern | 字符串重复子串序列

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli

2017-02-21 19:50:25 383

原创 35. Search Insert Position | 找数

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.

2017-02-20 19:40:52 232

原创 501. Find Mode in Binary Search Tree | 二叉搜索树重复的节点

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node c

2017-02-20 15:47:41 779

原创 231. Power of Two | 判断2的幂

Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.Subscribe to se

2017-02-19 21:14:17 239

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

2017-02-19 20:42:09 378

原创 121. Best Time to Buy and Sell Stock | 买股票的利润

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2017-02-19 20:03:52 264

原创 405. Convert a Number to Hexadecimal | 10进制整数转16进制数

Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexade

2017-02-18 16:03:20 275

原创 415. Add Strings | 大整数相加

Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.

2017-02-18 13:08:24 738

原创 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 iand j equals the distance between i and k (the order of t

2017-02-17 20:28:55 308

原创 350. Intersection of Two Arrays II | 查找两个数组重复

Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma

2017-02-17 16:45:30 188

原创 13. Roman to Integer | 罗马数组转整数

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.还是得会找规律呀。。。public class Solution { public int romanToInt(String s) { int num

2017-02-16 15:35:35 324

空空如也

空空如也

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

TA关注的人

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