![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
食鱼酱
一只努力向上的程序员
展开
-
[LeetCode]2.Add Two Numbers 超出数字范围问题
原题: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret...原创 2018-02-27 10:37:29 · 184 阅读 · 0 评论 -
全排列的递归实现(Java版)
public class AllSort{ public static void main(String[] args) { char buf[]={'a','b','c'}; perm(buf, 0, buf.length-1); } public static void per...原创 2018-03-10 11:40:28 · 2799 阅读 · 3 评论 -
动态规划从入门到精通(二)-棋盘类题目
题目:Leetcode 62. Unique PathsA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The r...原创 2018-07-20 11:17:27 · 2931 阅读 · 4 评论 -
[动态规划]一个一维维数组中只有1和-1,实现程序,求和为0的最长子串长度
一个一维维数组中只有1和-1,实现程序,求和为0的最长子串长度,如输入[1,-1,-1,1],输出为4。//核心思路//dp[i][j]表示从array[i]一直加到array[j]的和递推式:dp[i][j] = dp[i+1][j-1] + array[i] + array[j];判定:if(dp[i][j] == 0) max = max(max, j-1+1);...原创 2018-08-04 20:02:32 · 3117 阅读 · 2 评论 -
[Java编程]分苹果
n 只奶牛坐在一排,每个奶牛拥有 ai 个苹果,现在你要在它们之间转移苹果,使得最后所有奶牛拥有的苹果数都相同,每一次,你只能从一只奶牛身上拿走恰好两个苹果到另一个奶牛上,问最少需要移动多少次可以平分苹果,如果方案不存在输出 -1。 输入描述: 每个输入包含一个测试用例。每个测试用例的第一行包含一个整数 n(1 <= n <= 100),接下来的一行包含 n 个整数 ...原创 2018-08-10 09:53:52 · 982 阅读 · 0 评论 -
[Java编程]找出一个目录下的所有子目录和文件
private static void getDirectory(File file) { //获取该目录下的文件列表 File flist[] = file.listFiles(); if (flist == null || flist.length == 0) { return; } for (File f : flist) { ...原创 2018-08-02 11:58:44 · 1658 阅读 · 0 评论 -
[Java编程]迷宫问题(BFS)
给定一个大小为 N×M 的迷宫。迷宫由通道和障碍组成(0为可以通过,1为障碍),每一步可以向邻接的上下左右四格的通道移动。请求出从起点到终点所需的最小步数,题目保证一定有解。import java.util.*;public class Main { public static void main(String[] args) { int[][] tab = { ...原创 2018-08-12 16:26:46 · 4823 阅读 · 4 评论