ICode9

精准搜索请尝试: 精确搜索
  • leetcode1588-所有奇数长度子数组的和2022-09-04 14:02:45

      https://leetcode.cn/problems/sum-of-all-odd-length-subarrays/ 虽然知道几个嵌套循环暴力可以做,但是可以明显看出每一次都要经过很多重复计算,数组中每一个数字相加的次数是不同的,于是尝试看看相加的次数有什么规律。 其中大小为5的数组相加次数分别为3 4 5 4 3,大小为7的数

  • leetcode 409 Longest Palindrome 最长回文串(简单)2022-08-31 13:30:49

    一、题目大意 给定一个包含大写字母和小写字母的字符串 s ,返回 通过这些字母构造成的 最长的回文串 。 在构造过程中,请注意 区分大小写 。比如 "Aa" 不能当做一个回文字符串。 示例 1: 输入:s = "abccccdd" 输出:7 解释: 我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。

  • 328 Odd Eeven Linked list2022-07-12 02:01:07

            class Solution {     public ListNode oddEvenList(ListNode head) {         if(head==null) return null;         ListNode odd=head,even=head.next,evenHead=even;         while(even!=null&&even.next!=null){         

  • 328 add two number2022-07-12 02:00:37

            class Solution {     public ListNode oddEvenList(ListNode head) {         if(head==null) return null;         ListNode odd=head,even=head.next,evenHead=even;         while(even!=null&&even.next!=null){         

  • 325 add two nunber2022-07-12 02:00:30

    class Solution {     public ListNode oddEvenList(ListNode head) {         if(head==null) return null;         ListNode odd=head,even=head.next,evenHead=even;         while(even!=null&&even.next!=null){             odd.

  • Codewars note: 奇偶判定2022-07-10 11:03:17

    判断 奇数 偶数: Solution:  1 def even_or_odd(number): return 'Even' if number % 2 == 0 else 'Odd'   2 def even_or_odd(number): return ['Even', 'Odd'][number % 2]  

  • 力扣今日题-1217. 玩筹码2022-07-08 23:04:31

    1217. 玩筹码 思路: class Solution { public int minCostToMoveChips(int[] pos) { int odd = 0 ,even=0; for(int i = 0; i < pos.length; i++){ if(pos[i] % 2 == 0){ even++; }else{ odd++;

  • 2022-7-8 玩筹码2022-07-08 21:01:11

    来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/minimum-cost-to-move-chips-to-the-same-position 有 n 个筹码。第 i 个筹码的位置是 position[i] 。 我们需要把所有筹码移到同一个位置。在一步中,我们可以将第 i 个筹码的位置从 position[i] 改变为: position[i] + 2

  • [dp 记录] abc258Ex Odd Steps2022-07-08 08:32:26

    题意转化:给定 \(n\) 个整数和 \(S\),选一个从小到大排序的数列,\(0\) 和 \(S\) 必选,使相邻两数奇偶性不同,给出的 \(n\) 个数不能选。求方案数。 \(S \leq 10^{18},n \leq 10^5\) 看着非常 \(dp\),但是 \(S\) 极大,于是就是矩乘优化 \(dp\) 了。 令 \(dp_i\) 表示所选数均 \(\leq i\)

  • LeetCode103 二叉树的锯齿形层序遍历2022-07-02 15:02:07

    LeetCode103 二叉树的锯齿形层序遍历 使用两个栈进行模拟 + bfs # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class S

  • 叫高二上一调?简要题解 (ACD)2022-06-27 21:01:29

    A. 电压机制 题意转换为所有奇环的并排除掉所有偶环留下的边的个数 . 建出 DFS 树,然后只有返祖边可能构成环 . 于是类似树上差分,\(odd_u\) 统计奇环,\(even_u\) 统计偶环 . 如果一条返祖边 \(u\leftrightarrow v\) 形成奇环,则 \(odd_u\) 自增 \(1\),\(odd_v\) 自减 \(1\),偶环类似 .

  • 贴一个简单但是最近很喜欢的美观的代码2022-06-11 21:01:44

    #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { vector<int> number,even,odd; int a; while(cin>>a){ number.push_back(a); } for(int i=0;i<number.size();i+

  • 2022/6/3学习记录2022-06-03 12:00:24

    JS算法题 罗马数字转换器 把传入的数字转为罗马数字。 转换后的罗马数字字母必须都是大写 Solution: function convertToRoman(num) { var lookup = { M:1000, CM:900, D:500, CD:400, C:100, XC:90, L:50, XL:40, X:10, IX:9, V:

  • LeetCode 1524 Number of Sub-arrays With Odd Sum 思维2022-05-30 16:02:31

    Given an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo \(10^9 + 7\). Solution 注意 \(subarray\) 是连续的序列。注意的一点是: \(\text{odd+odd/even+even = even}\),因此只有当奇偶性相反时,

  • python装饰器(二)装饰器的使用2022-05-28 18:00:24

    装饰器的作用: *装饰器其实就是利用闭包功能对函数进行增强 *装饰器格式为: @闭包函数名 简单案例: def show(fun1): def show_in(): fun1() sumdate = 0 for i in range(1,101): if i%2 == 1 : sumdate += i pri

  • 267:回文序列II2022-04-22 21:01:56

    查看代码 //将原生解法转化为ACM解法的一个例子 #include<iostream> #include<cstring> #include<vector> using namespace std; int n; vector<string>ans; void dfs(vector<int>& count, string s) { if (s.size() == n) { ans.push_back(s);//长度够了返回

  • 「LTIME107」Odd Split2022-04-17 13:00:14

    「LTIME107」Odd Split 给定 \(N\) 和模数 \(\text{mod}\),对于 \(n=1\sim N\) 计算: 有多少个大小为 \(n\) 的排列 \(P\),满足它可以被划分成两个子序列,使得两个子序列的逆序对数均为奇数。 \(1\le N\le 10^6,10^8\le \text{mod}\le 10^9\),保证 \(\text{mod}\) 是奇数。 Solution

  • 1656D - K-good2022-03-26 19:01:46

    1656D - K-good n is k-good if and only if $ n \geq 1 + 2 + \ldots + k = \frac{k(k+1)}{2}.$ \(n \equiv 1 + 2 + \ldots + k \equiv \frac{k(k+1)}{2} \pmod{k}.\) It is clear that both conditions are necessary, and it turns out they're sufficie

  • 【Python】collections.Counter快速统计元素个数,免去手动构造字典的烦恼2022-03-20 11:02:09

    用法 用collections.Counter来快速统计元素个数: import collections a = collections.Counter("sdfdsgsdfdfssfd") #把所有元素出现的次数统计下来了 print(a) 输出结果: Counter({‘s’: 5, ‘d’: 5, ‘f’: 4, ‘g’: 1}) 具体案例 Leetcode 409. 最长回文串 可用colle

  • python中的内置函数2022-03-08 17:02:20

    filter函数用于过滤序列, 该接收两个参数,第一个为函数,第二个为序列,序列的每个元素作为参数传递给函数进行判断,然后返回 True 或 False,最后将返回 True 的元素放到新列表中 def check_odd(n):#找奇数 return n%2==1 list1=[1,2,3,4,5] list2 = list(filter(check_odd,list1))

  • clickhouse支持udf,通过ambda表达式使用2022-02-28 14:34:25

    UDF用户可通过添加lambda表达式,创建自定义Function CREATE FUNCTION linear_equation AS (x, k, b) -> k*x + b; SELECT number, linear_equation(number, 2, 1) FROM numbers(3); SELECT number, linear_equation(number, 2, 1) FROM numbers(3) Query id: 9a4a2978

  • jquery过滤选择器2022-02-22 13:30:00

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=d

  • 快速傅立叶变换2022-02-11 09:59:03

    已知 n n n 维向量 v ∈ C n

  • pat甲级World_Cup_Betting 1011世界杯投注2022-02-07 21:34:34

    原题 With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their mo

  • 分支结构_双分支结构2022-01-24 12:33:40

    双分支结构 语法结构: if 条件表达式: 条件执行体1 else: 条件执行体2 针对非A即B的选择情况 example:#判断一个整数是否为奇数或者偶数 num=int(input('Please input a number : ')) if num%2:#if num%2 == 1 is also OK print('odd') else: print('not odd')

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

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

ICode9版权所有