9 纸上得来终觉浅 绝知此事要躬行

尚未进行身份认证

我要认证

github.com/luqian2017

等级
TA的排名 6k+

LintCode 1814: Sum of all Subarrays (数学题)

1814.Sum of all SubarraysGiven a list of nums, return the sum of all subarrays.ExampleExample1:Input: nums = [1, 2, 3]Output: 20Explanation : {1} + {2} + {3} + {2 + 3} + {1 + 2} + {1 + 2 + 3} = 20Example2Input : [1, 2]Output : 6Explanatio.

2020-10-19 15:14:50

LintCode 859: Max Stack

859.Max Stack中文EnglishDesign a max stack that supports push, pop, top, peekMax and popMax.push(x) -- Push element x onto stack. pop() -- Remove the element on top of the stack and return it. top() -- Get the element on the top. peekMax() -- Retri.

2020-10-17 13:49:24

LintCode 1172: Binary Tree Tilt (二叉树好题)

1172.Binary Tree TiltGiven a binary tree, return the tilt of thewhole tree.The tilt of atree nodeis defined as theabsolute differencebetween the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt ...

2020-10-16 14:57:54

LintCode 1231: Minimum Moves to Equal Array Elements

1231.Minimum Moves to Equal Array ElementsGiven anon-emptyinteger array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.ExampleInput:[1,2,3]Output:3Expl...

2020-10-15 15:10:53

欧几里得算法和扩展欧几里得算法

欧几里德算法:定理:a 和 b 两个整数的最大公约数等于b 与 a % b的最大公约数形式化表示:假设a, b!=0, 则gcd(a, b) = gcd(b, a%b)。证明:1. 设 c = gcd(a, b), 则 a = cx, b = cy,且gcd(x,y)=12. 可知 a % b = a - k * b = cx - kcy = c (x - ky)3. 可知 c 也是a % b 的 factor (这里我们证明了c是b和a%b的公约数,下面要证明c是b和a%b的最大公约数,所以要证明

2020-10-10 01:44:43

LintCode 1870: number of substrings with all zeroes

1870.numberofsubstringswithallzeroesGivenastringstrcontainingonly0or1,pleasereturnthenumberofsubstringsthatareconsistof0.ExampleExample1:Input:"00010011"Output:9Explanation:Thereare5substringsof"0",There...

2020-10-09 13:34:02

Linux VIM 常见编辑命令小结

iAoO: 插入d x: 删除y: 复制p: 粘贴g G: 跳转/: 查找v: 可视化ctlr + v: 块操作:%s/old/new/g: 替换ctlr+z: 挂起fg: 返回%1: (zsh中%1等价于fg)

2020-10-08 13:57:54

LintCode 1796: K-Difference

1796.K-DifferenceInthischallenge,youwillbegivenanarrayofintegers,eachuniquewithinthearray,andanintegerrepresentingatargetdifference.Determinethenumberofpairsofelementsinthearraythathaveadifferenceequaltothetarget...

2020-10-08 11:53:03

LintCode 322: Chess Game

322.ChessGameInagameofchess,youaregiventwobinaryarrays:abinaryarrayqueenwithsizeN,whichrepresentsthecoordinatesofNqueens;abinaryarrayknightwithsizeM,whichrepresentsthecoordinatesofMknights.Aqueencanattackan...

2020-10-08 11:27:26

Linux shell 编程学习

1. shell中用到的特殊字符参考链接https://www.cnblogs.com/balaamwe/archive/2012/03/15/2397998.html# ; ;; . , / \ 'string'| ! $ ${} $? $$ $*"string"* ** ? : ^ $# $@ `command`{} [] [[]] () (())...

2020-10-06 12:37:34

LintCode 1648: max substring

1648.max substringGiven a string s, return the last substring of s in lexicographical order.ExampleExample 1:Input: "abab"Output: "bab"Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum .

2020-10-05 23:47:00

LintCode 930: Connected Components in List (link-list/map/set/union-find)

930.Connected Components in ListGiven a doubly linked list and an array of nodes. If the nodes are connected with each other(which means we can access any nodes through any one of them), we can consider them as one block. Find the number of blocks in th.

2020-10-05 03:49:25

C语言用二维数组作为函数入口参数的小结

C语言里面定义了二维数组int arr[100][200];那arr就是一个指针,指针类型是什么呢?是int(*)[200]。所以最自然的是用下面的func2(int (*a)[200]) 或func3(int a[][200]),这样main函数调用的时候直接用func2(arr)或func3(arr)就可以了。这里的a是一个一维指针,指向一个int数组,这个数组有200个元素。当然也可以用func0(int *a),但func0里面不能直接用a[i][j],因为编译器不认识。访问a[i][

2020-10-03 15:24:54

LintCode 45: Maximum Subarray Difference (MaxSubArray 变种)

45.Maximum Subarray DifferenceGiven an array with integers.Find twonon-overlappingsubGarraysAandB, which|SUM(A) - SUM(B)|is the largest.Return the largest difference.ExampleExample 1:Input:[1, 2, -3, 1]Output:6Explanation:The subarr...

2020-10-03 01:16:30

关于素数的算法小结

1. 判断一个数是不是素数解法1:最经典的版本 1 #include <stdio.h> 2 #include <math.h> 3 #include <stdbool.h> //C99 supports bool type 4 5 bool is_prime(int n) { 6 if (n <= 3) return n > 1; 7 int sqrt_n = sqrt(n); 8 9

2020-10-02 11:30:59

 Linux 文件系统学习

Linux 系统根目录下面的目录名 /bin,重要的二进制应用程序,包含二进制文件,系统的所有用户使用的命令都在这里 /boot,启动包含引导加载程序的相关文件 /dev,包含设备文件,终端文件,USB 或者连接到系统的任何设备 /etc,系统配置文件,启动脚本等,包含所有程序所需要的配置文件,也包含了启动/停止单个应用程序的启动和关闭 shell 脚本。注意 /etc/passwd和/etc/group跟用户强相关。 /home,本地主要路径,所有用户用 h.

2020-10-01 14:28:26

设计模式(OOD)学习

设计原则1) SOLID:Single Responsibility Principle:单一职责原则:一个东西就一个功能Open Closed Principle:开闭原则 修改的时候,要保留原来的功能Liskov Substitution Principle:里氏替换原则:避免子类重写父类中已经实现的方法Law of Demeter:迪米特法则 :尽可能的少暴露自己的接口,能不 public 就不 publicInterface Segregation Principle:接口隔离原则 1.

2020-09-27 08:43:29

LintCode 883: Max Consecutive Ones II

883.MaxConsecutiveOnesIIGivenabinaryarray,findthemaximumnumberofconsecutive1sinthisarrayifyoucanflipatmostone0.ExampleExample1:Input:nums=[1,0,1,1,0]Output:4Explanation:Flipthefirs...

2020-09-25 15:12:26

LintCode 1872: Minimum Cost to Connect Sticks (最小堆好题)

1872.MinimumCosttoConnectSticksYouhavesomestickswithpositiveintegerlengths.YoucanconnectanytwosticksoflengthsXandYintoonestickbypayingacostofX+Y.Youperformthisactionuntilthereisonestickremaining.Returnth...

2020-09-21 22:24:14

秒杀系统中乐观锁(Optimistic Lock)和悲观锁(Pessimistic Lock)的对比

参考九章的讲座。悲观锁:用户先判断是否拿到锁,如果没有拿到,则排队等待。若可以拿到,则减库存,然后释放锁,这时排队等待的线程有一个可以得到锁。SQL实现: 注意"for update"表示执行完step 1语句后,把product_id = xxxxx 锁住,其它线程则不能对product_id = xxxxx操作。//step 1:select * from stock where product_id = xxxxx for udpate//step 2:udpate stock

2020-09-21 01:24:05

查看更多

勋章 我的勋章
  • 领英
    领英
    绑定领英第三方账户获取
  • GitHub
    GitHub
    绑定GitHub第三方账户获取
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 1024勋章
    1024勋章
    #1024程序员节#活动勋章,当日发布原创博客即可获得
  • 勤写标兵Lv4
    勤写标兵Lv4
    授予每个自然周发布9篇以上(包括9篇)原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。