ICode9

精准搜索请尝试: 精确搜索
  • 20211108-01 Two Sum2021-11-08 09:34:13

    20211108-01 Two Sum https://leetcode-cn.com/problems/two-sum/ python # 题目给了边界限制,所以代码中没做判断 class Solution(object): def twoSum(self, nums, target): dic = {} for idx, num in enumerate(nums): if target - num in dic:

  • Trie2021-11-05 21:02:32

    字典树Trie 大概是老师讲完后的无聊产物。 和第二天发现自己记不得垂死病中惊坐起颓废的话。 Trie是用来存字符串的, 其基本思想是将相同前缀的字符串放在一起, 建成一棵树, 又称字典树 可以看下面的图片理解怎么存的。 请原谅这张图我自己都看不下去。 然后就喜闻乐见的代码qaq voi

  • CF 1366D. Two Divisors(线性筛)2021-11-04 22:02:56

    #include <cstdio> #include <cstring> #include <cmath> #include <ctime> #include <cassert> #include <algorithm> #include <random> #include <chrono> #include <iostream> #include <functional> #incl

  • 1005 Spell It Right (20 分)(字符串处理)2021-11-04 20:34:54

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specification Each input file contains one test case. Each case occupies one line which contains an N (<= 10100)

  • python-从MultiIndex的索引列获取唯一值2021-11-04 18:32:02

    我知道可以通过重置索引来获取DataFrame的唯一值,但是有没有办法避免此步骤并直接获取唯一值? 鉴于我有:  C A B 0 one 3 1 one 2 2 two 1 我可以: df = df.reset_index() uniq_b = df.B.unique() df = df.set_index(['A','B']) 有熊猫内置的方法吗? python p

  • pandas写入数据2021-11-04 18:00:11

    a = ['a.jpg', 'c.jpg', 'b.jpg'] b = [1,2,3] out_dict = {'image' : a, 'label' : b} print(out_dict) df_one = pd.DataFrame(out_dict) print(df_one) df_two = df_one.sort_values('image') print(df_two)

  • python 中使用 'is' 要注意其判断值为对象,不要用来判断变量值是否相等2021-11-04 14:03:27

    w3school 的解释: The is keyword is used to test if two variables refer to the same object. The test returns True if the two objects are the same object. The test returns False if they are not the same object, even if the two objects are 100% equal. Use the

  • json解析之C++库nlohmann / json2021-11-02 09:04:42

    项目地址:nlohmann_json_cmake_fetchcontent/json.hpp at master · ArthurSonzogni/nlohmann_json_cmake_fetchcontent · GitHub 设计目标 直观的语法。在像Python这样的语言中,JSON就像是一个一流的数据类型。我们使用了现代C++的所有操作符魔法,在您的代码中实现了相同的感

  • 06-Panda统计计算和描述2021-10-31 23:33:00

    import numpy as np import pandas as pd df=pd.DataFrame([[1.4,np.nan],[7.1,-4.5], [np.nan,np.nan],[0.75,-1.3]], index=['a','b','c','d'], columns=['one','

  • CF1555B Two Tables2021-10-31 15:34:44

    题目链接 //#include<bits/stdc++.h> //using namespace std; //int main() //{ // int t; cin >> t; // int n, m; // int x1, y1, x2, y2; // int w, h; // while (t -- ) // { // cin >> n >> m >> x1 >> y1 >> x2 >> y2 &

  • AGC040F Two Pieces2021-10-29 21:03:18

    AGC040F Two Pieces Description 有两个棋子初始点都在坐标 \(0\) ,两个棋子之间没有区别,总共要进行 \(n\) 次操作,每次操作是如下操作其中之一: 选择一个棋子向前移动一步。 选择位置较后的那个棋子,直接移动到位置较前的那个棋子的位置。 问 \(n\) 次操作后两个棋子分别在位置 A,B

  • [LeetCode 解题笔记] 1. Two Sum2021-10-27 13:04:34

    题目描述: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the

  • 【第一道水题】A. Two Subsequences2021-10-26 18:32:50

    题目来源:Problem - A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1602/problem/A 题干:  第一道水题,结果被想复杂了。这个只需要将字符串进行排序,然后输出一个最小元素和一个缺少最小元素的字串即

  • Two pointer2021-10-25 23:31:08

    I.何为Two pointer 基本问题 给定一个正整数递增序列和一个正整数M,求序列中两个不同位置的a,b使得a+b==M,打印a,b。 合并两个递增正整数序列。 解决方案 遍历:O(n^2) two pointer: O(n)【充分利用了序列的递增特性】 代码实现 #include<stdio.h> int main() { int a[5] = {1

  • Codeforces Round #751 (Div. 2) A. Two Subsequences2021-10-25 18:32:02

    显然去除最小的字母,然后输出剩下的字符即可。 但是第一次写忘记了一个特殊情况:所有字母都相等且等于z。写代码时下意识地认为给出的字符串总有小于z的,就算等于z,也可以输出一个z,但没有考虑到此时index没有被更新。 #include<cstdio> #include<iostream> #include<cstring> usi

  • 【Java题解】剑指 Offer 56 - II. 数组中数字出现的次数 II2021-10-24 20:32:46

    在一个数组 nums 中除一个数字只出现一次之外,其他数字都出现了三次。请找出那个只出现一次的数字。 示例 1: 输入:nums = [3,4,3,3] 输出:4 示例 2: 输入:nums = [9,1,7,9,7,9,7] 输出:1 限制: 1 <= nums.length <= 10000 1 <= nums[i] < 2^31 方法一: 使用位运算以及有限状

  • 【CF1398】E. Two Types of Spells(set)2021-10-22 12:05:54

    题目链接:https://codeforces.com/problemset/problem/1398/E 分析 不难发现,每次我们要让能被双倍使用的咒语尽量大,能被双倍使用的咒语数量就是1类咒语的数量。而能被双倍使用的咒语即是除了第一次使用的1类咒语外的所有咒语。 根据贪心的思想,第一次使用的1类咒语肯定是1类咒

  • 比较两个集合中过滤出相同的元素2021-10-19 11:33:15

    // 集合一 List one = new ArrayList(); one.add("jim"); one.add("tom"); one.add("jack"); // 集合二 List two = new ArrayList(); two.add("jim"); two.add("tom"); two.add("jack"); two.add("good");

  • 指针运算找到数组中最大和第二大元素2021-10-17 19:04:37

    编写下列函数:void find_two_largest(const int*a,int n,int*largest,int*second_largest);a指向长度为n的数组。函数从数组中找出最大和第二大元素,并把它们分别储存到由largest和second_largest指向的变量中,要求使用指针算术运算而不是取下标来访问数组元素。 //从数组中找出最大和

  • 四数之和2021-10-17 15:31:43

    题目 解答 public static List<List<Integer>> fourSum(int[] nums, int target) { Arrays.sort(nums); ArrayList<Integer> list = new ArrayList<>(); for (int num : nums) { list.add(num); }

  • ABC222 D - Between Two Arrays(dp,差分优化)2021-10-15 15:35:16

    题意: 解法: d[i][j]表示前i个数,c[]末尾为j的方案数. 设l=a[i],r=b[i]. 发现每次转移需要将d[i][j]加到d[i+1][]的一个区间, 那么复杂度就变成O(n^3)的了. 但是由于是连续区间,所以可以用差分优化以下, 复杂度就降为O(n^2)了 code: #include<bits/stdc++.h> // #define MULT

  • [LeetCode]2.Add Two Numbers 两数相加(Java)2021-10-13 15:00:24

    原题地址: add-two-numbers 题目描述: 给你两个非空的链表,表示两个非负的整数。它们每位数字都是按照逆序的方式存储的,并且每个节点只能存储一位数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外,这两个数都不会以 0 开头。 示例 1: 输入:l1 =

  • Medium: Add Two Numbers No.22021-10-13 14:01:37

    Link list by Python 1. link list 数据结构: 数组是由“元素”组成的,字典是由“键值对”组成的,每个数据结构都有它的基本单元。而link list的基本单元就是node:节点。 所以想要弄清楚link list的结构,就要先明白node的结构。 node是一个由两部分组成的unit,一部分是next,指向下一

  • D - Between Two Arrays(前缀和优化dp)2021-10-12 23:02:28

    D - Between Two Arrays(前缀和优化dp) 见官方题解,先考虑朴素dp,然后在基础上前缀和优化。 时间复杂度: O ( n m )

  • 653. Two Sum IV - Input is a BST2021-10-12 11:01:00

    use std::borrow::Borrow; use std::cell::RefCell; use std::collections::HashMap; use std::ops::Index; use std::rc::Rc; /** 653. Two Sum IV - Input is a BST https://leetcode.com/problems/two-sum-iv-input-is-a-bst/ Given the root of a Binary Search Tree and

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有