
编程题
huangjingjinglll
一起加油(ง •̀_•́)ง
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
二叉树的遍历:递归,非递归
public class Tree { public class Node{ public Node left; public Node right; public int val; public Node(int val) { this.val = val; } } //前序递归 public void preOrderRecur(Node he...原创 2020-03-06 12:53:46 · 275 阅读 · 0 评论 -
编程题:二叉树的最大距离
import java.util.*;public class Main{ public static class TreeNode{ TreeNode left; TreeNode right; int val; public TreeNode(int val){ ...原创 2020-02-29 00:11:14 · 188 阅读 · 0 评论 -
编程题:把二叉树打印成多行(非递归)
import java.util.*;/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class...原创 2020-02-27 02:12:49 · 177 阅读 · 0 评论 -
编程题:把二叉树打印成多层(递归)
import java.util.ArrayList;/*public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/publ...原创 2020-02-27 01:57:53 · 172 阅读 · 0 评论 -
编程题:链表中的环
/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode EntryNodeOfLoop(ListNode pHe...原创 2020-02-27 01:38:17 · 164 阅读 · 0 评论 -
编程题:数组中只出现一次的数
题目描述一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。//num1,num2分别为长度为1的数组。传出参数//将num1[0],num2[0]设置为返回结果//先用亦或,相同则为0,不同则为1,最后得到的就是单独的2个数的亦或,是2个数不同的位置,//选第一个1的位置,将数组分为2组,则2个数分到不同组,相同的数分到相同组,则可以在分好的组...原创 2020-02-27 01:19:24 · 245 阅读 · 0 评论 -
编程题:平衡二叉树
题目描述输入一棵二叉树,判断该二叉树是否是平衡二叉树。public class Solution { public boolean IsBalanced_Solution(TreeNode root) { if(root == null){ return true; } return IsBalanced_Solu...原创 2020-02-27 00:48:47 · 418 阅读 · 0 评论 -
编程题:树的深度
题目描述输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。public class Solution { public int TreeDepth(TreeNode root) { if(root == null){ return 0; } ...原创 2020-02-27 00:35:49 · 272 阅读 · 0 评论 -
编程题:正则表达式匹配
请实现一个函数用来匹配包括’.‘和’‘的正则表达式。模式中的字符’.‘表示任意一个字符,而’'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"abaca"匹配,但是与"aa.a"和"ab*a"均不匹配public class Solution { public boolean match(char[]...原创 2020-02-25 13:51:11 · 325 阅读 · 0 评论 -
编程题:表示数值的字符串
请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100",“5e2”,"-123",“3.1416"和”-1E-16"都表示数值。 但是"12e",“1a3.14”,“1.2.3”,"±5"和"12e+4.3"都不是。用正则public class Solution { public boolean isNumeric(char[] str) { ...原创 2020-02-25 12:40:41 · 159 阅读 · 0 评论 -
编程题:287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...原创 2020-02-23 00:21:49 · 165 阅读 · 0 评论 -
编程题:56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps, m...原创 2020-02-22 23:40:39 · 226 阅读 · 0 评论 -
编程题:17. Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is give...原创 2020-02-22 23:18:10 · 118 阅读 · 0 评论 -
编程题:55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you ...原创 2020-02-22 22:06:25 · 109 阅读 · 0 评论 -
编程题:3sum,乱序数组
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contai...原创 2020-02-22 20:55:15 · 127 阅读 · 0 评论 -
编程题:getMin栈
题目描述:实现一个特殊功能的栈,在实现栈的基本功能的基础上,再实现返回栈中最小元素的操作。CODEimport java.util.*;public class Main{ public static void main(String[]args){ getMinStack ms = new getMinStack(); Scanner scanner = new...原创 2020-02-20 20:02:44 · 270 阅读 · 0 评论 -
编程题:最长可整合子数组
题目描述先给出可整合数组的定义:如果一个数组在排序之后,每相邻两个数的差的绝对值都为1,或者该数组长度为1,则该数组为可整合数组。例如,[5, 3, 4, 6, 2]排序后为[2, 3, 4, 5, 6],符合每相邻两个数差的绝对值都为1,所以这个数组为可整合数组给定一个数组arr, 请返回其中最大可整合子数组的长度。例如,[5, 5, 3, 2, 6, 4, 3]的最大可整合子数组为[5,...原创 2020-02-16 23:52:48 · 256 阅读 · 0 评论 -
编程题:用两个栈实现队列,支持队列的基本操作
题目要求:用两个栈实现队列,支持队列的基本操作CODEimport java.util.*;public class Main{ public static void main(String[] args){ QueueByStack sq = new QueueByStack(); Scanner scanner = new Scann...原创 2020-02-20 19:54:57 · 508 阅读 · 0 评论 -
编程题:不重复3SUM
题目描述给定排序数组arr和整数k,不重复打印arr中所有相加和为k的不降序三元组例如, arr = [-8, -4, -3, 0, 1, 2, 4, 5, 8, 9], k = 10,打印结果为:-4 5 9-3 4 9-3 5 80 1 90 2 81 4 5[要求]时间复杂度为O(n^2)空间复杂度为O(1)输入描述:第一行有两个整数n, k接下来一行有n个整数表...原创 2020-02-17 00:02:38 · 182 阅读 · 0 评论 -
编程题:不重复2sum
题目描述给定排序数组arr和整数k,不重复打印arr中所有相加和为k的不降序二元组例如, arr = [-8, -4, -3, 0, 1, 2, 4, 5, 8, 9], k = 10,打印结果为:1, 92, 8[要求]时间复杂度为O(n),空间复杂度为O(1)输入描述:第一行有两个整数n, k接下来一行有n个整数表示数组内的元素输出描述:输出若干行,每行两个整数表示答案...原创 2020-02-16 23:58:46 · 317 阅读 · 0 评论 -
编程题:在行和列都排好序的矩阵中找指定的数
题目描述给定一个N×M的整形矩阵matrix和一个整数K, matrix的每一行和每一列都是排好序的。实现一个函数,判断K是否在matrix中[要求]时间复杂度为O(N+M),额外空间复杂度为O(1))。输入描述:第一行有三个整数N, M, K接下来N行,每行M个整数为输入的矩阵输出描述:若K存在于矩阵中输出"Yes",否则输出"No"CODE//递归,一般从右上角或者左下角...原创 2020-02-16 23:44:35 · 223 阅读 · 0 评论