自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

有梦的博客

有梦就不怕痛,追逐梦想的路上,我永不止步

  • 博客(63)
  • 收藏
  • 关注

原创 1032 Sharing java

To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example,...

2019-05-31 08:13:56 221

原创 1074 Reversing Linked List /1025 反转链表 java

Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then you must output 3→2→1→6→5→4; ifK=4, ...

2019-05-30 21:21:38 200

原创 1063 Set Similarity java

Given two sets of integers, the similarity of the sets is defined to beN​c​​/N​t​​×100%, whereN​c​​is the number of distinct common numbers shared by the two sets, andN​t​​is the total number of ...

2019-05-30 11:22:42 242

原创 1022 Digital Library java

A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number a...

2019-05-30 09:42:55 173

原创 1071 Speech Patterns java

People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker...

2019-05-29 21:58:58 217

原创 1086 Tree Traversals Again java

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...

2019-05-29 15:48:32 182

原创 1020 Tree Traversals java

Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the cor...

2019-05-29 15:14:12 247

原创 根据后序遍历和中序遍历建二叉树 java

public static TreeNode create(int[] post, int postLeft, int postRight, int[] in, int inLeft, int inRight) { if (postLeft &g...

2019-05-29 15:12:37 1457

原创 1039 Course List for Student java

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes ...

2019-05-29 13:19:12 300

原创 1051 Pop Sequence java

Given a stack which can keepMnumbers at most. PushNnumbers in the order of 1, 2, 3, ...,Nand pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of t...

2019-05-29 10:46:19 316

原创 二叉树中和为某一值的路径 java

输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前)import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;/**publi...

2019-05-28 22:35:11 457

原创 数据流中的中位数 java

如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。我们使用Insert()方法读取数据流,使用GetMedian()方法获取当前读取数据的中位数。import java.util.ArrayList;import java.util.PriorityQue...

2019-05-28 21:34:59 484

原创 二叉搜索树的第k个结点 java

给定一棵二叉搜索树,请找出其中的第k小的结点。例如, (5,3,7,2,4,6,8) 中,按结点数值大小顺序第三小结点的值为4。import java.util.ArrayList;/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; ...

2019-05-28 20:58:16 334 1

原创 按之字形顺序打印二叉树 java

请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推。import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;import java.util.Stack;/*public class Tre...

2019-05-28 20:35:54 288

原创 把二叉树打印成多行 java

从上到下按层打印二叉树,同一层结点从左至右输出。每一层输出一行。import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode...

2019-05-28 14:58:03 195

原创 拷贝二叉树 java

/*class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public TreeNode copyTreeNode(TreeNode ro...

2019-05-28 14:54:43 816

原创 二叉搜索树的后序遍历序列是否合法 java

输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { return judge(sequence, 0, sequence.leng...

2019-05-28 10:20:22 220

原创 二叉树层序遍历 java

从上往下打印出二叉树的每个节点,同层节点从左至右打印。import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right...

2019-05-28 09:25:06 5842

原创 二叉树的深度 java

输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { ...

2019-05-28 09:09:14 236

原创 输入两棵二叉树A,B,判断B是不是A的子结构 java

/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution { /**...

2019-05-27 22:37:32 499

原创 重建二叉树 java

输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。/** * Definition for binary tree * public class TreeNode { * int val; *...

2019-05-27 22:02:32 206

原创 孩子们的游戏(圆圈中最后剩下的数) java

题目描述每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为牛客的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个大圈。然后,他随机指定一个数m,让编号为0的小朋友开始报数。每次喊到m-1的那个小朋友要出列唱首歌,然后可以在礼品箱中任意的挑选礼物,并且不再回到圈中,从他的下一个小朋友开始,继续0...m-1报数....这样下去.....

2019-05-27 17:13:26 130

原创 计算字符个数 java

题目描述写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。输入描述:输入一个有字母和数字以及空格组成的字符串,和一个字符。输出描述:输出输入字符串中含有该字符的个数。示例1输入复制ABCDEF A输出复制1import java.util.Scanner;...

2019-05-27 14:04:40 771

原创 明明的随机数 java

题目描述明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作(同一个测试用例里可能会有多组数据,希望大家能正确处理)。In...

2019-05-27 14:03:17 905 2

原创 字符串分隔 java

连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。输入描述:连续输入字符串(输入2次,每个字符串长度小于100)输出描述:输出到长度为8的新字符串数组示例1输入复制abc123456789输出复制abc000001234567890000000...

2019-05-27 14:01:04 171

原创 1024 Palindromic Number java

A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...

2019-05-27 11:12:20 228

原创 1023 Have Fun with Numbers java

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number con...

2019-05-27 10:48:11 209

原创 1008 Elevator java

The highest building in our city has only one elevator. A request list is made up withNpositive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 sec...

2019-05-27 09:14:04 197

原创 1049 数列的片段和 java

给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列 { 0.1, 0.2, 0.3, 0.4 },我们有 (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4) 这 10 个片段。给定正整数数列,求出全部...

2019-05-26 14:24:44 368 1

原创 1019 数字黑洞 java

给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的6174,这个神奇的数字也叫 Kaprekar 常数。例如,我们从6767开始,将得到7766 - 6677 = 10899810 - 0189 = 96219621 - 12...

2019-05-26 13:15:10 312

原创 1040 有几个PAT java

字符串APPAPT中包含了两个单词PAT,其中第一个PAT是第 2 位(P),第 4 位(A),第 6 位(T);第二个PAT是第 3 位(P),第 4 位(A),第 6 位(T)。现给定字符串,问一共可以形成多少个PAT?输入格式:输入只有一行,包含一个字符串,长度不超过10​5​​,只包含P、A、T三种字母。输出格式:在一行中输出给定字符串中包含多少个...

2019-05-26 10:52:33 260

原创 1044 Shopping in Mars java

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position ...

2019-05-25 10:07:51 154

原创 1067 Sort with Swap(0, i) java

Given any permutation of the numbers {0, 1, 2,...,N−1}, it is easy to sort them in increasing order. But what ifSwap(0, *)is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2...

2019-05-24 10:39:32 178

原创 1038 Recover the Smallest Number java

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229...

2019-05-23 21:55:23 152

原创 1037 Magic Coupon java

The magic shop in Mars is offering some magic coupons. Each coupon has an integerNprinted on it, meaning that when you use this coupon with a product, you may getNtimes the value of that product b...

2019-05-23 20:10:59 192

原创 1033 To Fill or Not to Fill java

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different ga...

2019-05-23 14:54:07 198

原创 1020 月饼 java

月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 ...

2019-05-23 12:48:38 302

原创 1023 组个最小数 java

at_user页面绑定至拼题A账号。绑定后,原PAT网站的提交将被合并至拼题A网站用户的对应题目集中。返回1023组个最小数(20分)给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558。现给定数字,请编写程...

2019-05-23 12:18:44 208

原创 1055 The World's Richest java

1055The World's Richest(25分)Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, ...

2019-05-23 11:01:47 218

原创 1028 List Sorting java

Excel can sort records according to any column. Now you are supposed to imitate this function.Input Specification:Each input file contains one test case. For each case, the first line contains two...

2019-05-22 17:06:48 221

空空如也

空空如也

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

TA关注的人

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