zoukankan      html  css  js  c++  java
  • leetcode1825,802,583,501

    1825

        public static int maxProfit(int[] prices) {
            if (prices.length == 0 || prices.length == 1){
                return 0;
            }
            int sel = 0;
            int min = prices[0];
            for (int i = 1; i < prices.length; i++) {
                if (prices[i] > min){
                    sel = Math.max(prices[i]-min,sel);
                }else {
                    min = prices[i];
                }
            }
    
            return sel;
        }

    802

    static Boolean[] flag ;
    
        public static List<Integer> eventualSafeNodes(int[][] graph) {
            List<Integer> list = new ArrayList<>();
            flag = new Boolean[graph.length];
            LinkedList<Integer> stack = new LinkedList<>();
            for (int i = 0; i < graph.length; i++) {
                if (iter(i,graph,stack)){
                    list.add(i);
                }
            }
            return list;
        }
    
        public static boolean iter(int k,int[][] graph,LinkedList<Integer> stack){
            //已经记录过状态的直接返回
            if (flag[k] != null){
                return flag[k];
            }
            stack.push(k);
            //设置为false
            flag[k] = false;
            for (int i = 0; i < graph[k].length; i++) {
                if (stack.contains(graph[k][i])){
                    stack.pop();
                    return false;
                }else {
                    if (!iter(graph[k][i],graph,stack)){
                        stack.pop();
                        return false;
                    }
                }
            }
            stack.pop();
            flag[k] = true;
            return true;
        }

    583

    public static int minDistance(String word1, String word2) {
            int[][] exist = new int[word1.length()+1][word2.length()+1];
            for (int i = 0; i <= word1.length(); i++) {
                for (int j = 0; j <= word2.length(); j++) {
                    if (i == 0 || j == 0){
                        exist[i][j] = 0;
                    }else {
                        if ( word1.charAt(i-1) == word2.charAt(j-1)){
                            exist[i][j] = exist[i-1][j-1]+1;
                        }else {
                            exist[i][j] = Math.max(exist[i-1][j],exist[i][j-1]);
                        }
                    }
                }
            }
            return word1.length()+word2.length()- 2* exist[word1.length()][word2.length()];
        }

    501 

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode(int x) { val = x; }
     * }
     */
    class Solution {
         Map<Integer,Integer> map = new HashMap<>();
         Set<Integer> result = new HashSet<>();
        Integer maxCount = 1;
    
        public  int[] findMode(TreeNode root) {
            if (root == null){
                return new int[0];
            }
            search(root);
    
            int[] arr = new int[result.size()];
            int k = 0;
            for (Integer integer : result) {
                arr[k++] = integer;
            }
            return arr;
        }
    
        public  void search(TreeNode root){
            Integer count = map.get(root.val);
            count = count == null?1:++count;
            map.put(root.val,count);
            if (count == maxCount ){
                result.add(root.val);
            }
            if (count > maxCount){
                result.clear();
                result.add(root.val);
                maxCount = count;
            }
            if (root.right != null){
                search(root.right);
            }
            if (root.left != null){
                search(root.left);
            }
        }
    }
  • 相关阅读:
    A survey of best practices for RNA-seq data analysis RNA-seq数据分析指南
    DART: a fast and accurate RNA-seq mapper with a partitioning strategy DART:使用分区策略的快速准确的RNA-seq映射器
    中科院生物信息学题目整理
    生物信息学题目整理: 陈润生
    第六章 Windows应用程序对键盘与鼠标的响应 P121 6-8
    第七章 资源在Windows编程中的应用 P157 7-8
    第四章 Windows的图形设备接口及Windows绘图 P83 4-6
    Android Fragment 你应该知道的一切
    Android Fragment 真正的完全解析(下)
    Android Fragment 真正的完全解析(上)
  • 原文地址:https://www.cnblogs.com/hetutu-5238/p/14297889.html
Copyright © 2011-2022 走看看