首页 > TAG信息列表 > SEEN

LeetCode 0133 Clone Graph

原题传送门 1. 题目描述 2. Solution 1 1、思路分析 DFS 2、代码实现 package Q0199.Q0133CloneGraph; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /* DFS */ public class Solution { private Map<Integer, Node> seen = new

**316. Remove Duplicate Letters

  class Solution { public String removeDuplicateLetters(String s) { int[] lastIndex = new int[26]; for (int i = 0; i < s.length(); i++){ lastIndex[s.charAt(i) - 'a'] = i; // track the lastIndex of character pr

Stream 去重方法引用

/** * 过滤接口函数 * * @param keyExtractor 属性引用 * @param <T> 属性引用泛型 * @return Predicate 函数接口 */ public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { Set<Object> seen = ConcurrentHas

golang 空结构体

今天做力扣141题环形链表,碰到了空结构体这个问题,有点意思,记录一下 原文题解: func hasCycle(head *ListNode) bool { seen := map[*ListNode]struct{}{} for head != nil { if _, ok := seen[head]; ok { return true } seen[he

山东大学软件工程应用与实践——PIG代码分析(七)

2021SC@SDUSC 今天接着上文细说walk()方法子类遍历能力的体现 目录 2021SC@SDUSC DependencyOrderWalker 递归过程 DependencyOrderWalker DependencyOrderWalker按照依赖顺序访问plan,即一个node被访问的前提是它的前辈们已经被访问过了。这个访问顺序相当于,按照拓扑顺序访问

leetcode 797. All Paths From Source to Target | 797. 所有可能的路径(回溯法)

题目 https://leetcode.com/problems/all-paths-from-source-to-target/ 题解 回溯,中规中矩,直接上代码。 class Solution { int N; public List<List<Integer>> allPathsSourceTarget(int[][] graph) { N = graph.length; boolean[][] g = new boo

Python广度优先和深度优先

#定义一个图的结构 graph={ 'A':['B','C'], 'B':['A','C','D'], 'C':['A','B','D','E'], 'D':['B','C',&

Leetcode 1971. Find if Path Exists in Graph [Python]

BFS 从start遍历到end,每一次que弹出节点是end,返回true,否则,把此节点加入到seen set中,并入队。遍历完成后,未找到end节点,代表和start直接或间接相连的节点中没有end节点。返回false。注意特殊情况,只有一个节点时。 class Solution: def validPath(self, n: int, edges: List

Python---去除txt文件中重复的行数

采用python中set()的概念,通过遍历原始文档中的元素,并将其添加到set()中,然后根据set()的性质来判断新的元素是否要被添加到新的文档中去。最终生成的新的文档即满足所需。 #coding:utf-8 readDir = "./original_file.txt" writeDir = "./new_file.txt" outfile=open(writeDir,"w"

java8 利用 ConcurrentHashMap list根据 某个属性 去重

//自定义方法private static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) { Map<Object, Boolean> seen = new ConcurrentHashMap<>(); return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE

DFS与BFS的python实现

最近复习题目,发现对图的python实现比较无知,所以实现一下。 在python中采用字典来表示图的结构,访问非常方便。 BFS与DFS非递归的写法最大的差别是在遍历的过程中路过的结点一个用队列保存,一个用栈保存,其他结构几乎是一样的! 这么理解的话应该很好记忆了 直接上代码 graph={ 1:[

剑指Offer 49.丑数

https://leetcode-cn.com/problems/chou-shu-lcof/solution/chou-shu-by-leetcode-solution-0e5i/ 小根堆,注意小根堆的定义方式 class Solution { public: int nthUglyNumber(int n) { vector<int> factors = {2, 3, 5}; unordered_set<long> seen

最大单词长度乘积

    变量简洁正确完整思路 枚举两个单词,wordsi wordsj 如果没有重复单词就更新答案ans,判断重复用哈希集 seen遍历wordsi,然后遍历wordsj看是否存在 class Solution { public: int maxProduct(vector<string>& words) { int ans=0,n=words.size(); for(in

264. 丑数 II

264. 丑数 II 给你一个整数 n ,请你找出并返回第 n 个 丑数 。 丑数 就是只包含质因数 2、3 和/或 5 的正整数。 示例 1: 输入:n = 10 输出:12 解释:[1, 2, 3, 4, 5, 6, 8, 9, 10, 12] 是由前 10 个丑数组成的序列。 示例 2: 输入:n = 1 输出:1 解释:1 通常被视为丑数。 提示: 1 <= n

VUE学习三,控制元素v-if

控制切换一个元素是否显示也相当简单 一、示范代码 <div id="app-3"> <p v-if="seen">现在你看到我了</p> </div> var app3 = new Vue({ el: '#app-3', data: { seen: true } }) 二、结果如下图所示     三、在控制台输入 app3.seen = false,之前显示的消息会

Java ASM系列:(031)修改已有的方法(优化-删除-复杂的变换)

本文属于[Java ASM系列一:Core API](https://blog.51cto.com/lsieun/2924583)当中的一篇。 ## 1. 复杂的变换 ### 1.1 stateless transformations The stateless transformation does not depend on **the instructions that have been visited before the current one**. 举几

[CF1498D] Bananas in a Microwave

前言 你所能够依靠的,只有你自己。 题目 CF 洛谷 题目大意: 输入两个整数 \(n,m\) 表示操作数与目标香蕉数量。 接下来输入 \(n\) 个操作,每个操作有三个整数 \(t_i,x_i,y_i\)。令你当前的香蕉数量为 \(k\)。 如果 \(t_i=1\),你可以从 \([0,y_i]\) 中选择一个数 \(a_i\) ,将 \(\lceil

【小工具】1.需要对txt存放的测试数据做去重处理

采用集合去重,在新文件里逐行写入,达成目的old_file = "D:/testdata/memberId.txt"  #old result_file = "D:/testdata/memberId_new.txt" #new lines_seen = set() out_file = open(result_file, "w") f = open(old_file, "r") for line in f:   if lin

idea更改MySQL依赖版本时错误:Duplicated tag: ‘properties‘ (position: START_TAG seen ...

标签重复了,pom.xml文件中已经有了标签!! 刷新即可

快乐数

快乐数 class Solution { private int getNext(int n) { int totalSum = 0; while (n > 0) { int d = n % 10; n = n / 10; totalSum += d * d; } return totalSum; } public boolean isH

java8 利用流给实体类去重方法

// 数据去重 利用原理 map去重 List noRepeatList = bookList.stream.filter(distinctByKey(Book::getName)).collect(Collectors.toList());` /** * 数据流去重方法 * 如果多个参数,使用添加即可 * @param keyExtractor * @param <T> * @return */ public static <T> Predic

Python 排序最长英文单词链(列表中前一个单词末字母是下一个单词的首字母)

本文主要介绍排序最长的单词链的方法,列表中每个元素相当于一个单词,要实现列表中前一个单词末字母是下一个单词的首字母,并且这个链是最长的。 使用递归实现 words = ['giraffe', 'elephant', 'ant', 'tiger', 'racoon', 'cat', 'hedgehog', 'mouse'] def get_resul

[leetcode] 1034. Coloring A Border

Description Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid square at that location. Two squares belong to the same connected component if and only if they have the same color and are next to each other in

List<Map> 获取key重复数据及过滤对应key重复数据

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Predicate; public class StreamEx{     //过滤重

vue实现移入移出事件

Html <i class="icon" @mouseenter="enter(index)" @mouseleave="leave()"></i> JS methods:{ enter(index){ this.seen = true; this.current = index; }, leave(){ this.seen = fa