leetcode
coffeein-free
【飞鸟CS】公众号
展开
-
Leetcode 735 :行星碰撞——详细分析及python实现
分析:1、只有行星相向才可能发生碰撞,即[5, -5]发生碰撞,[-5, 5]不发生碰撞2、由第3个例子获得思路每次仅发生一次碰撞,定义函数check_neighbor()查找每次发生碰撞的第一个行星位置,若找不到则返回当前list3、对于每次发生碰撞的两个行星,可以确定第一个行星(index)为正,第二个(index+1)为负,故比较其绝对值即可确定淘汰下来哪个行星...原创 2022-07-13 15:40:03 · 553 阅读 · 0 评论 -
LeetCode 645: 错误集合
桶排序思想class Solution { public int[] findErrorNums(int[] nums) { int[] button = new int[10001]; for(int i=0;i<nums.length;++i) { button[nums[i]]++; } int lost=0, bonus=0; for(int i=1;i<=nums.length;++i) { if(原创 2021-07-05 13:51:49 · 74 阅读 · 0 评论 -
2021-5-17 LeetCode 993 堂兄弟结点
借鉴了以一下高赞大神的 写了个C的#include<stdio.h>#include<stdlib.h>struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right;};void create(TreeNode* &BT){ char c; scanf("%c", &c); if(c!='#'){ BT=(TreeNode*)mall原创 2021-05-17 19:46:54 · 90 阅读 · 3 评论