- 博客(22)
- 收藏
- 关注
原创 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].Note: Recursive solution is trivial,
2016-08-05 09:33:09 195
原创 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 the s
2016-08-03 10:19:52 220
原创 Top K Frequent Element
Given a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of unique ele
2016-08-01 06:27:28 187
原创 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.利用递归便可轻松解决/** * De
2016-08-01 06:24:03 154
原创 Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The result can be in
2016-08-01 06:22:04 143
原创 Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For e
2016-08-01 06:16:49 221
原创 数据结构(java)----BinarySearchTree
写一个BST的java语言实现import org.omg.CORBA.UserException;public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> { private static class BinaryNode<AnyType> { BinaryNode(Any
2016-08-01 06:11:42 269
原创 数据结构(java)----MyArrayList
最近看的书叫“数据结构与算法分析,java语言描述”,里面有讲到各种数据结构的实现。今天先写出最简单的一部分,ArrayList的实现
2016-07-16 22:48:54 182
原创 最大的矩形
问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi。这n个矩形构成了一个直方图。例如,下图中六个矩形的高度就分别是3, 1, 6, 5, 2, 3。 输入格式 请找出能放在给定直方图里面积最大的矩形,它的边要与坐标轴平行。对于上面给出的例子,最大矩形如下图所示的阴影部分,面积是10。 第一行包含一个整数n,即矩形的数量(1 ≤ n ≤
2016-07-16 22:05:30 248
原创 ISBN号码
问题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位是识别码,例如0-670-82162-4就是一个标准的ISBN码。ISBN码的首位数字表示书籍的出版语言,例如0代表英语;第一个分隔符“-”之后的三位数字代表出版社,例如670代表维京出版社;第二个分
2016-07-16 21:51:47 344
原创 出现次数最多的数
问题描述 给定n个正整数,找出它们中出现次数最多的数。如果这样的数有多个,请输出其中最小的一个。 输入格式 输入的第一行只有一个正整数n(1 ≤ n ≤ 1000),表示数字的个数。 输入的第二行有n个整数s1, s2, …, sn (1 ≤ si ≤ 10000, 1 ≤ i ≤ n)。相邻的数用空格分隔。 输出格式 输出这n个次数中出现次数最多的数。如果这样的数有多个,输出其中最小的
2016-07-16 21:47:16 248
原创 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
2016-07-14 22:44:46 223
原创 Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
2016-07-14 22:37:49 138
原创 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9to4 / \ 7 2 / \ / \ 9 6 3 1
2016-07-14 22:34:50 234
原创 Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The result can be in
2016-07-14 22:29:04 172
原创 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.Subscribe to see which companies asked this
2016-07-13 20:29:37 168
原创 Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, r
2016-06-02 00:24:42 173
原创 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me
2016-05-31 15:30:15 205 1
原创 Nim Game
开始刷起了LeetCode~~ Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes
2016-05-31 15:06:03 153
原创 programming-challenges110201 jolly jumpers
programming-challenges里面的题 主要方法是利用标记数组和遍历 #include<stdio.h>#include"math.h"int main(){ int i,j,k,temp,cnt; int visit[5000]; bool flag; int num[5000]; int n; while(scanf("%d"
2015-07-17 15:54:37 205
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人