Java
vita0590
一个菜鸟成长的地方~~~~
展开
-
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 · 148 阅读 · 0 评论 -
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 · 217 阅读 · 0 评论 -
数据结构(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 · 267 阅读 · 0 评论 -
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 · 136 阅读 · 0 评论 -
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 · 181 阅读 · 0 评论 -
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 · 192 阅读 · 0 评论 -
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 · 213 阅读 · 0 评论 -
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 · 148 阅读 · 0 评论 -
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 · 217 阅读 · 0 评论 -
最大的矩形
问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi。这n个矩形构成了一个直方图。例如,下图中六个矩形的高度就分别是3, 1, 6, 5, 2, 3。 输入格式 请找出能放在给定直方图里面积最大的矩形,它的边要与坐标轴平行。对于上面给出的例子,最大矩形如下图所示的阴影部分,面积是10。 第一行包含一个整数n,即矩形的数量(1 ≤ n ≤原创 2016-07-16 22:05:30 · 241 阅读 · 0 评论 -
ISBN号码
问题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位是识别码,例如0-670-82162-4就是一个标准的ISBN码。ISBN码的首位数字表示书籍的出版语言,例如0代表英语;第一个分隔符“-”之后的三位数字代表出版社,例如670代表维京出版社;第二个分原创 2016-07-16 21:51:47 · 314 阅读 · 0 评论 -
出现次数最多的数
问题描述 给定n个正整数,找出它们中出现次数最多的数。如果这样的数有多个,请输出其中最小的一个。 输入格式 输入的第一行只有一个正整数n(1 ≤ n ≤ 1000),表示数字的个数。 输入的第二行有n个整数s1, s2, …, sn (1 ≤ si ≤ 10000, 1 ≤ i ≤ n)。相邻的数用空格分隔。 输出格式 输出这n个次数中出现次数最多的数。如果这样的数有多个,输出其中最小的原创 2016-07-16 21:47:16 · 243 阅读 · 0 评论 -
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 · 185 阅读 · 1 评论 -
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 · 165 阅读 · 0 评论 -
数据结构(java)---MyLinkedList
看着书自己写了一遍linkedlist,以及其中的迭代器的实现原创 2016-07-24 11:20:25 · 277 阅读 · 0 评论 -
数据结构(java)----MyArrayList
最近看的书叫“数据结构与算法分析,java语言描述”,里面有讲到各种数据结构的实现。今天先写出最简单的一部分,ArrayList的实现原创 2016-07-16 22:48:54 · 178 阅读 · 0 评论 -
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 · 162 阅读 · 0 评论 -
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 · 167 阅读 · 0 评论 -
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 · 229 阅读 · 0 评论 -
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 · 130 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array原创 2017-02-27 20:12:02 · 201 阅读 · 0 评论