GO学习项目---家庭收支记账软件 主菜单功能实现:func (f *FamilyAccount) MainMenu() { for { fmt.Println("-----------家庭收支记账软件-----------") fmt.Println(" 1.收支详细") fmt.Println(" 2.登记收入") fmt.Println(" 3.登记支出") fmt.Println(" 4.退 出") fmt.Print("
OJ---盛最多水的容器 一开始用的双for循环移动左右指针,提交超时。然后发现只需要移动高度较低的那个指针就行class Solution { public int maxArea(int[] height) { if(height.length<=1){ return 0; } if(height.length==2){ if(height[0]!=0 && height[1]!=0){
OJ---数据分类处理 import java.util.*;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String one[] = in.nextLine().split(" "); String two[] = in.nextLine().split(" "); int Ln = Integer.va
OJ---查找组成一个偶数最接近的两个素数 import java.util.*;public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int arr[] = new int[n]; Arrays.fill(arr,1); ArrayList<Integer> lis
OJ---腐烂的橘子 运用广度优先搜索(BFS)class Solution { public int orangesRotting(int[][] grid) { int count=0;//记录新鲜橘子 int N = grid.length;//记录数组的行 int M = grid[0].length;//记录数组的列 Queue<int[]> queue = new LinkedList<>(); for(
OJ---接雨水问题 import java.util.*;public class Solution { /** * max water * @param arr int整型一维数组 the array * @return long长整型 */ public long maxWater (int[] arr) { // write code here int top = 0; int max = 0; f
OJ---二叉搜索树的后序遍历序列 即如果把中序序列当做栈的压入序列,那么后序序列是该栈的一个弹出序列import java.util.*;public class Solution { public boolean VerifySquenceOfBST(int [] sequence) { int[] arr = sequence.clone(); Arrays.sort(arr); return IsPopOrder(arr,sequence); } publi
OJ---从上往下打印二叉树 通过队列来实现二叉树的广搜public class Solution { public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) { Queue<TreeNode> queue = new LinkedList<TreeNode>(); ArrayList<Integer> arr = new ArrayList<>();
OJ---称砝码 import java.util.*;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int num[] = new int[n]; int weight[] = new int[n]; for (int i = 0; i &l
OJ---最小覆盖子串 import java.util.*;public class Solution { /** * * @param S string字符串 * @param T string字符串 * @return string字符串 */ public String minWindow (String S, String T) { // write code here int l=0,r=0; i
OJ---最长回文子串 import java.util.*;public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param A string字符串 * @return int整型 */ public int getLongestPalindrome (String A) { // write code here if(A
OJ---最长连续递增序列 记录当前连续递增序列的开始下标和结束下标,遍历数组的过程中每次比较相邻元素,根据相邻元素的大小关系决定是否需要更新连续递增序列的开始下标class Solution { public int findLengthOfLCIS(int[] nums) { int max = 0; int start = 0; if(nums.length==1){ return 1; } for(int i=0;
OJ---组合 class Solution { public List<List<Integer>> combine(int n, int k) { List<List<Integer>> res = new ArrayList<>(); if(k==0||n<k){ return res; } Deque<Integer> path = new A
OJ---有重复字符串的排列组合 class Solution { LinkedList<String> list = new LinkedList<>(); public String[] permutation(String S) { dfs(S.toCharArray(),0); return list.toArray(new String[0]); } public void dfs(char[] c,int k){ if(k==
OJ---括号的最大嵌套深度 import java.util.*;class Solution { public int maxDepth(String s) { int count = 0; int num = 0; for(char ch:s.toCharArray()){ if(ch=='('){ count++; }else if(ch=='['){ cou
OJ---有效括号序列 import java.util.*;public class Solution { /** * * @param s string字符串 * @return bool布尔型 */ public boolean isValid (String s) { // write code here if(s==null){ return false; } Stack