milk_bread milk_bread
关注数: 4 粉丝数: 91 发帖数: 1,363 关注贴吧数: 14
坐标魔都,最近半个月找了五六个红包车的经历 为啥想到找红包车,因为想在哈罗APP上得到红包车徽章。 更因为红包车有1.8x的奖励 不到两块钱。找十辆车可以买一张月卡了。其实是最近装修给坑钱了心情不好。决定压缩每月交通开支,都骑哈罗不坐地铁了。 红包车先从公司,和家自己熟悉的地方附近找。首先现在是月卡用户。 No1自家同一片的老小区隔一条马路,门洞里面楼梯下停了一辆崭新的车车。(好奇这么新的车就算停在一楼,怎么也能变成红包车) No2 找到在公司旁边老小区,那个小区我们经常穿过去走捷径,如果是没去过的小区我还有点不好意思乱入。小区正在修路,红包车也在靠近围墙的角落。打开没故障。 No3因为骑车回家也有16公里,提前看好地图沿路哪里有很多红点路过就停下看看找得到红包车就换,如果找不到就再开一个正常车离开。(红包车规则,骑了红包车关锁,再马上骑不是红包车就没有奖励了),这次实践没有成功,沿着徐汇滨江在世博那边有一片封闭的区域是有。只是踩点,下次看看哪里可以去。 No4附近地铁站旁边停车场里面有四辆。有两辆给压在垃圾堆里面了。 还有两辆靠边,骑了一辆去地铁站结果距离太近当作公益了。 第二辆骑回家ok。 目前还没找满十辆。 只是每天碰运气,上下班路上留意下。因为骑车上下班就已经是一种锻炼身体又节省的做法了。红包车就是锦上添花,顺便觉得自己做了好事。路上也在思考希望能和自己和解从那个亏钱的阴影中走出来。
1366. Rank Teams by Votes 一道中等难度。读完就有思路结果做了一天。 In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition. The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter. Given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above. Return a string of all teams sorted by the ranking system. Example 1: Input: votes = ["ABC","ACB","ABC","ACB","ACB"] Output: "ACB" 题目是要求 投票以后根据票数多少 进行再次排序。 比如A B两个如果选A做首选的多 那么A在前面 反之则B在前, 如果选他们为首选的人一样多。那么再比较选他们两个做第二选择的人的多少。以此类推。都相同就按字母顺序排序 这道题目看完我就有了两个想法 凡是这样的字母表的 一般都会用一个 int[26]的数组来计数。 比用dictionary还清爽 比较的规则看起来是递归了 于是动手写代码。结果犯了n次数组越界。 我的天。。。。 越界到怀疑人生。 最后虽然accept了 但是一天过去了。 我一点都不高兴。应该总结点儿什么了
想问问吧友有没有谁牙髓炎 补牙成功。或者什么自愈的案例吗? 来看了好几天。牙齿也反复快一个月了。 rt 有耐心的可以看我啰嗦这个牙的前前后后。 是一颗磨牙上面的。 开始是最早自己作觉得舌头舔着有点不平好像一个洞(完全不疼)。去社区医院问问。 人家说拿给你补点儿银汞合金的吧。 记得那时候补牙也没有磨牙? 大约是五六年前的事情。 后来前年觉得这个牙窝沟上舔起来又有什么,觉得是不是过去银汞出现热胀冷缩之类的?然后去了一个能用医保但是不是三家的医院,找了两次医生看了都说没什么问题呀。 作罢一阵子。 然后去年总是习惯的舔那颗牙觉得不平的地方。然后去了一个三家医院,拍了个小牙片,就是只给那附近牙拍的那种,然后一个年轻的小姐姐医生说是这个牙有临面龋。 于是噩梦开始了我还印象中的补牙就是填补一下,结果是大刀阔斧的 磨了一个大洞。然后补上树脂。 这一以后更加不舒服了。 感觉像是塞牙了,再后来就是这半边嘴巴从这个牙渗透出的 总觉得有咸味,有时候吃完饭是甜味。 一年过去了,终于2月11吃了一个自己烤箱出品的东西牙齿开始发病了。 尝到了各种疼。一跳一跳的。火辣辣的,酸胀的。 这都是我过去从来没有体会过的,算是长见识了。但是其他我也不想多体会了。我晚上倒是不会疼。一般都是和吃过东西有关,估计是吃的酸甜热刺激到那边了。我已经不用那边吃东西了。但是嘴巴塞多的时候应该也会溜过去有点。 我渐渐发现规律以后,就开始不喝太热的水,刷牙什么也注意不要刺激到那颗牙,吃饭都用另外一边了。 现在暂时平静了。可是那边的牙依然能渗透出咸味。就用嚼口香糖解决。 准备疫情过去找一个全市看牙最好的医院去看。不去那个坑人的榜上无名的三甲医院把我牙坑成这样的地方了。而且医生还比较傲慢。昨天过去开点儿消炎药,回答问题都是挑着的,爱理不理的。这样的医生和电视上的怎么差距这么大。
981. Time Based Key-Value Store 基于时间的键值对 两个月前做过提交了 7遍都超时了。这次回去再试试看,结果还提交了两次错误答案。最后回归超时。 Create a timebased key-value store class TimeMap, that supports two operations. 创造一个类TimeMap 用来基于时间的键值对,并且构建两个方法 1. set(string key, string value, int timestamp) Stores the key and value, along with the given timestamp. Set赋值,存储key, value, timestamp 时间戳 2. get(string key, int timestamp) Get 取值,根据key和时间戳timestamp Returns a value such that set(key, value, timestamp_prev) was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the one with the largest timestamp_prev. If there are no values, it returns the empty string (""). 返回<=这个时间戳的值,如果有多个时间戳满足条件,则选择最大的那个时间戳时候的值,如果没有结果返回“” public class TimeMap { private Dictionary<string, Dictionary<int, string>> keysDt; /** Initialize your data structure here. */ public TimeMap() { keysDt = new Dictionary<string, Dictionary<int, string>>(); } public void Set(string key, string value, int timestamp) { var history = new Dictionary<int, string>(); if (keysDt.ContainsKey(key)) { history = keysDt[key]; history.Add(timestamp, value); keysDt[key] = history; } else { history.Add(timestamp, value); keysDt.Add(key, history); } } public string Get(string key, int timestamp) { string res = ""; if (keysDt.ContainsKey(key)) { Dictionary<int, string> history = keysDt[key]; if (history.ContainsKey(timestamp)) return history[timestamp]; var allKeys = history.Keys.Where(x => x <= timestamp).OrderByDescending(x => x); if (allKeys.Count() == 0) { return ""; } else { return history[allKeys.FirstOrDefault()]; } } return res; } } 看了其他C#的答案 这个linq查询的也超时了 我自己的二分查找也超时了。 public string Get(string key, int timestamp) { string res = ""; if (keysDt.ContainsKey(key)) { Dictionary<int, string> history = keysDt[key]; if (history.ContainsKey(timestamp)) return history[timestamp]; int[] times = new int[history.Count]; int i = 0; foreach (int k in history.Keys) { times[i] = k; i++; } Array.Sort(times); int start = 0; int end = times.Length - 1; while (start + 1 < end) { if (times[start + (end - start) / 2] < timestamp) { start = start + (end - start) / 2; } else { end = start + (end - start) / 2; } } if (timestamp >= times[end]) res = history[times[end]]; else if (timestamp < times[start]) res = ""; else res = history[times[start]]; } return res; } 额的神呀 两个月以后并没有灵光乍现。 有没有大神帮我想想 是不是C#就没有好的数据结构能搞定了。
437. Path Sum IIIEasy 确定是easy吗? easy级别,再把题目梳理一下 437. Path Sum IIIEasy You are given a binary tree in which each node contains an integer value. 给你一二叉树,每个节点的值都是整数。 Find the number of paths that sum to a given value. 找到又几种路径其中节点的和等于给定的值。 The path does not need to start or end at the root or a leaf, but it must go downwards(traveling only from parent 路径不必从根节点到叶子节点。但是必须是从上到下。也就是需要从父节点到字节的的顺序。 nodes to child nodes). The tree has no more than 1,000 nodes and the values are in the range -1,000,000 to 1,000,000. 树最多有1000个节点。值得范围从-1000000到1000000 Example: root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8 10 / \ 5 -3 / \ \ 3 2 11 / \ \ 3 -2 1 Return 3. 返回3,因为有三条这样得路径 The paths that sum to 8 are: 1. 5 -> 3 2. 5 -> 2 -> 1 3. -3 -> 11 我写了一个算法。先遍历从根节点到叶子的所有路径 这个例子中就四条。放在一个list中 然后一个个拿出来 看有没有从前到后顺序加等于 sum的 结果算重复了 因为5->3 有两条路径都包括。哇顿时觉得有必要和大家分享一下。看看是不是在遍历的时候就加好呢? 会重复计算的代码。C#写呃 private List<List<int>> paths = new List<List<int>>(); public int PathSum(TreeNode root, int sum) { int combines = 0; WalkTree(root, new List<int>()); foreach (List<int> path in paths) { for (int i = 0; i < path.Count; i++) { int adds = path[i]; for (int j = i + 1; j < path.Count; j++) { adds += path[j]; if (adds == sum) combines++; } } } return combines; } private void WalkTree(TreeNode root, List<int> history) { if (root != null) { history.Add(root.val); if (root.left == null && root.right == null) { paths.Add(history); } else { List<int> historycopy = new List<int>(history); WalkTree(root.left, history); WalkTree(root.right, historycopy); } } }
957. Prison Cells After N Days 是不是位运算? 偷看了别人算法 有八个牢房。有空的,也有有犯人的。 There are 8 prison cells in a row, and each cell is either occupied or vacant. 每天,牢房要重新分配一下。规则如下 Each day, whether the cell is occupied or vacant changes according to the following rules: 如果这个牢房相邻的两个房间都是空的。或者都有人的。那么下次这个房间就要安排犯人 If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. 否则,下一次就要空着。 Otherwise, it becomes vacant. (值得注意的是,牢房是排成一排的,所以第一间和最后一间并没有两个相邻的房间。) (Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.) 这个表示牢房的数组 cells, cells[i]==1 有人 cells[i]==0 没人 We describe the current state of the prison in the following way: cells[i] == 1 if the i-th cell is occupied, else cells[i] == 0. 有最初牢房的状态。求N天以后牢房是怎么安排的。 Given the initial state of the prison, return the state of the prison after N days (and N such changes described above.) Example 1: Input: cells = [0,1,0,1,1,0,0,1], N = 7Output: [0,0,1,1,0,0,0,0]Explanation: The following table summarizes the state of the prison on each day:Day 0: [0, 1, 0, 1, 1, 0, 0, 1]Day 1: [0, 1, 1, 0, 0, 0, 0, 0]Day 2: [0, 0, 0, 0, 1, 1, 1, 0]Day 3: [0, 1, 1, 0, 0, 1, 0, 0]Day 4: [0, 0, 0, 0, 0, 1, 0, 0]Day 5: [0, 1, 1, 1, 0, 1, 0, 0]Day 6: [0, 0, 1, 0, 1, 1, 0, 0]Day 7: [0, 0, 1, 1, 0, 0, 0, 0] Example 2: Input: cells = [1,0,0,1,0,0,1,0], N = 1000000000 Output: [0,0,1,1,1,1,1,0] 超时的算法~~ 算了近一分钟才跳结果。当然在leetcode那边就直接down了。 public int[] PrisonAfterNDays(int[] cells, int N) { if(N==0) return cells; while(N>0){ cells=PassDay(cells); N=N-1; } return cells; } private int[] PassDay(int[] cells){ int[] res=new int[8]; for(int i=1;i<7;i++){ if(cells[i-1]==cells[i+1]){ res[i]=1; }else{ res[i]=0; } } return res; } 如果是位运算,我就缴械投降了。。。 感觉位运算要漂移到电子电路领域。
spark 布朗熊飞丢炸机,半个月的揪心和懊恼,今天终于捡回来了 坐标魔都,买了才半个月的spark 每次都是一键返航来返航的,最后提控回家。 在某个下班的傍晚超出视距飞行,看着遥控器上上上,转圈圈,云台俯仰,方向左左右右前前后感觉像是在打游戏。。。。飞行器开始有些黄色的提示自己也有点不确信,又按下一键返航,然后飞行器就是去了连接。 从此开启一条找飞机的旅程。 DJI GO 4 app里面找飞机的菜单位置都不太记得在哪儿。模糊记得有一次地铁里面玩手机看到过。点出来,向红色箭头找去。傍晚的天说黑就黑了。感觉要开着手电去照那些树丛草丛了。心里还有点担心如果到了附近会不会有人正等着我处理他的财产人身伤害。。。 结果马路上商务楼外,并没有这样的人(万幸万幸)。 因为还是新手 对app功能 遥控器提示都比较迟钝。 (错过了飞行器还有电的宝贵时间。)先去找了比较接近的位置的一个大楼一层的工作人员。也不知道是做什么的,后来知道似乎是一个比较德高望重的(惭愧)。然后这位绅士叫了几个保安大哥一起帮我找寻。然后我注意到遥控器上的灯是绿色的。然后我打开飞行界面看到还有图传(但是提示倾斜角度过大不能起飞,(现在我也要再说自己操作随意。怎么拿过来就要起飞。操作不假思索呀。。)),图传也看不清是什么黑乎乎,受飞行器指示灯影响还看到红色的反光一阵阵。 在找到断电以后(也扩大范围在附近的围墙里面也找了)决定提控回家。回去网上学习别人炸机找回的经验。 因为偶的spark失联以后又连上过遥控器的,所以我相信最后的找飞机显示的坐标。到网上下载了一个奥维互动地图(也是看知乎上面有人找飞机时候用的)把最后的经纬度输入。定位显示在一幢大楼的楼顶。找物业,自己也上去看了一次并没有。这时候大疆的售后分析结果也来了说飞机没有任何问题,建议也是在返航路线上的高楼返航一面找找。另外就是八五折买个新的保留一个月,并且之前飞机的care也可以转过去,丝毫没有心动,感觉我能找回来。 后来奢侈如我。到咸鱼上买了台二手的mavic air(正赶上mavic 2 出来这个九成新的带care和两块电池的air价格和我官网买的标配加care的spark一样) 飞到可疑坐标,终于在楼顶斜坡排水的沟渠看到了。再去物业求助,领导很爽快,打电话找人陪我去楼顶上的设备间,去到对应一侧的边缘捡回来了,happy ending。 最后一点总结:心存敬畏,好好读说明书,DJI的说明书已经很简短了。一厚本但是其实多语言,内容没几页,嫌字小去DJI官网都有PDF放大看的清楚。以后也不超视距,绕道大楼丛中了。一键返航慎用,越是情况不稳定越不能用。 另外心存感恩。找了一路好多热心的人们。他们的nice,帮助,建议,让我在第一时间都没有觉得沮丧。觉得现在魔都并不冷漠,和去到的山里乡里一样古道热肠。更加要做一个负责任的玩家。
1 下一页