Mshuang
Mshuang
全部文章
分类
题解(16)
归档
标签
去牛客网
登录
/
注册
Mshuang的博客
迎着曙光,绽放自己的生命之花
全部文章
(共16篇)
题解 | #最长回文子串#
中心扩散法。注意中心值奇数偶数个的问题 /** * NC17 最长回文子串 获取最长回文子串;回文子串:正反读相同; * @param str * @param n * @return */ public int getLongestPalindro...
2021-08-11
0
359
题解 | #反转字符串#
/**字符串装字符数组处理,双指针交换两指针的值 public static String solve (String str) { // write code here char[] chars = str.toCharArray(); int l...
2021-08-11
0
341
题解 | #子数组的最大累加和问题#
/****动态规划,数组值累加 >0取累加值 <0 取0。*/ public static int getMaxSubArraySum(int [] array){ if (array.length==1){return array[0];} int [...
2021-08-11
0
245
题解 | #寻找第K大#
public class NC88 { public static void main(String[] args) { int[] a={3,7,1,2,9,4,5,3,7}; int kth = findKth(a, 9, 2); System.out.pri...
2021-08-11
0
223
题解 | #合并两个有序的数组#
//双指针注意指针移动情况。有序数组比较尾部数据即可; public static void merge(int A[], int m, int B[], int n) { int[] ints = Arrays.copyOf(A, m + n); A=ints; ...
2021-08-10
0
257
题解 | #最小的K个数#
/*****冒泡排序取前面k个数。*/ public static ArrayList<integer> GetLeastNumbers_Solution(int [] input, int k) { ArrayList<integer>arrayList=ne...
2021-08-10
0
317
题解 | #在二叉树中找到两个节点的最近公共祖先#
/****方法判断一个树基本结构上有没有需要找的数,list存放节点;利用递归找出所有节点*/ public static boolean getPathToNode(TreeNode root, int node, List<integer> path){ if (root...
2021-08-10
0
268
题解 | #最长无重复子数组#
/** @Author: Mr.huang @Date: 2021/08/10/9:32 @Description: NC41 最长无重复子数组 利用双指针做窗口,利用哈希去重 /public class NC41 { public static void main(String[] ar...
2021-08-10
0
295
题解 | #跳台阶#
/***f(n)=f(n-1)+f(n-2) 主要对这个进行优化、动态规划方法最优*/ 方法一if (target <= 2) { return target; } int pre2=1,pre1=2; int ans=0; ...
2021-08-09
0
268
题解 | #求二叉树的层序遍历#
二叉树层序遍历用队列来处理。队列先进先出。add()。remove()、offer()、poll(); /** @Author: Mr.huang @Date: 2021/08/09/14:37 @Description: NC15 求二叉树的层序遍历 给定一个二叉树,返回该二叉树层序遍历的结...
2021-08-09
0
328
首页
上一页
1
2
下一页
末页