- 博客(15)
- 收藏
- 关注
原创 Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota
2015-06-25 21:44:34 376
原创 Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at most
2015-06-24 23:12:18 361
原创 Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi
2015-06-24 22:25:57 390
原创 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe
2015-06-15 22:42:21 462
原创 Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, i
2015-06-14 15:18:09 441
原创 Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.题目解析:将一个矩阵中0所在行,以及所在列都置为0.方法一:将矩阵中,0的行和列的下标保存下来,并且分别去除里面重复的下标,之后遍历矩阵,将记录的这些行和列均置为0.代码如下:cla
2015-06-12 23:31:55 391
原创 Search in Rotated Sorted Array && Search in Rotated Sorted ArrayII
Search in Rotated Sorted ArraySuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to s
2015-06-12 22:34:58 330
原创 Search a 2D Matrix
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.The first integer of each
2015-06-12 21:52:48 374
原创 Spiral Matrix && Spiral Matrix II
Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [
2015-06-10 15:29:00 441
原创 Find Minimum in Rotated Sorted Array I II
Find Minimum in Rotated Sorted Array ISuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.
2015-06-10 10:05:33 478
原创 Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?题目解读:将一个矩阵顺时针旋转90度。方法一:如下图所示,先转置,之后和变换的单位矩阵相乘
2015-06-09 15:35:34 411
原创 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 line i is at (i, ai) and (i, 0). Fin
2015-06-09 12:03:29 393
原创 leetcode--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].解题思路:求一串数字的
2015-06-08 15:56:59 452
原创 N个for改成while的方法
问题如下:手机上面的数字键均对应了几个字符,譬如2对应了a,b,c。问题是当输入一段数字后,求出所有可能的字符组合,(可以想象一下发短信时候的状况,每当按几个数字键后,均给出可能的汉语拼音,当然这个要求就更高了,本题只要求给出所有可能的组合)。举个例子输入4,2键后,则给出GA,GB,GC,HA,HB,HC,IA,IB,IC组合。当然对于大多数人来说就是几层循环就搞定了,每层遍历,内部输出
2015-06-08 15:39:00 2191
原创 leetcode-Minimum Depth of Binary Tree &&Maximum Depth of Binary Tree
1.Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.解题思路:求一棵二叉树的最短路径(从根节点到叶子节点)。
2015-06-03 23:26:51 441
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人