LeetCode Database Department Highest Salary 184

184. Department Highest Salary The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 70000 | 1 | | 2 | Henry | 80000 | 2 | | 3 | Sam | 60000 | 2 | | 4 | Max | 90000 | 1 | +----+-------+--------+--------------+ The Department table holds all departments of the company. ...

September 12, 2016 · 2 min · 281 words · Me

LeetCode Database Consecutive Numbers 180

180. Consecutive Numbers Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 1 | | 6 | 2 | | 7 | 2 | +----+-----+ For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times. ...

September 11, 2016 · 1 min · 173 words · Me

LeetCode Database Second Highest Salary 176

176. Second Highest Salary Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null. 大体意思 写 SQL 查询出第二高薪水的 Id。如何没有第二高,则返回 null ...

September 11, 2016 · 2 min · 257 words · Me

LeetCode Database Rising Temperature 197

197. Rising Temperature Given a Weather table, write a SQL query to find all dates’ Ids with higher temperature compared to its previous (yesterday’s) dates. +---------+------------+------------------+ | Id(INT) | Date(DATE) | Temperature(INT) | +---------+------------+------------------+ | 1 | 2015-01-01 | 10 | | 2 | 2015-01-02 | 25 | | 3 | 2015-01-03 | 20 | | 4 | 2015-01-04 | 30 | +---------+------------+------------------+ For example, return the following Ids for the above Weather table: ...

September 11, 2016 · 1 min · 127 words · Me

刚刚毕业的两个月小结

走出校园已经两个月了,因为之前的暑期也没怎么在家待过,大一在中康、大二在腾骏、大三在大为,大四毕业也就是现在,所以也没有什么特别的感觉。可以说,这两个月也做了些事情,学了些东西的。 从学校毕业,最直接的影响就是自己更加专注于计算机知识,不用再为学业担心。确定了先走技术的道路,也让自己不那么迷茫做什么。工作规律,自己开始读读书,才觉的读书是件有意思的事。也逼着自己常常写点东西,主要是觉的:写东西的时候自己会主动的思考,文笔练着练着也就能进步吧。 (一) DMV 是毕业后自己第一个项目,全栈开发。初版两周上线,后有花了一周多的时间编写了答题记录的功能。其中的收获是:项目框架的搭建和前端入门知识。原来的项目搭建都不是自己做的,也一直觉的是一件很难的事情。也许就是因为没有做过才觉的难,做过之后也觉的不过如此。项目的页面不多,但都是自己一点点写的,HTML JS 原来也就是自己改改,没有完整写过,这次算是一次不错的锻炼。写前端的时候才发现现在的前端真的是日新月异 AngularJS React 好多好多自己都没有听过的东西,也是从 Mengqi 那里了解到了很多。可惜的是自己没有实际的用上这些,如有机会一定尝试。 DMV 项目流量平平,因为有 Domain 类项目的工作,DMV 的维护就暂时放置了,还是心有不舍的。期间和 John 聊过一次关于产品的事基本总结为: 产品项目是会有失败的,有流量的项目才有维护的意义。 大型项目只有成功与失败之分,没有中间项,失败将代价很大。 不一定要留住用户。 更小的成本更高的流量,高流量后就可以做很多的事。 (二) Domain 信息类项目,使用的架构和 DMV 一致,逻辑更加简单。自己主要做了数据整理,收获是关于 SQL 命令。SQL 就可以直接处理很多的事情。使用了 RMI 做数据同步,用反射写了一段程序,是一次有突破的尝试。 一次看到自己年初的简历,笑了。自己是真敢写,能写个 Hello World 就敢标成了解。从会用到原理,是接下要走的路。 (三) 最近在看设计模式和算法的书,一直在做 LeetCode 的题。设计模式没用过,逮到能用机会绝不错过。算法健脑,刚刚开始接触觉的挺有意思,对数据结构也是种了解。 (四) 再次参加舍友的婚礼,又个结婚了。大一奶了一口,现在成真。祝福 Lu&Feifei。 (五) 来说说程序员那无处安放的创造力 有了锤子想找钉子是很正常的原始冲动,但我们必须认识到,创造力对于程序员这个职业来讲,是锦上添花的东西。如果你没有强大的工程能力,那么创造力也不过是无本之木。所以扎扎实实的把工程基础打好,这是最根本的。 在此基础上,我比较推荐程序员采用内外两条线来培养自己。在公司内的项目上采取相对保守的策略,尽力把稳定性做到最好,培养出自己卓越的工程能力;然后在公司外的开源项目和自己的独立项目上,采用一些新的技术、实践一些新的想法、充分发挥自己的创造力,梦想还是要有的,对吧。 这样做最明显的好处是,你可以了解到新技术和激进方案的优缺点,从而在进行方案选型时,有更多的依据;还有一个职业发展上的好处:如果不是主负责人,公司的项目往往不能代表你的能力;但独立项目却可以作为一个非常好的能力证明出现在你的简历里边。 你可以是一个身怀绝技的手艺人,在自己家里你尝试各种手法各种风格的个人作品;但当你参与颐和园这种级别的工程时,好好的把自己负责的石头雕成总设计师要求的样子就好 —— 毕竟这个时代一个人已经很难负责整个项目了。这就是我所理解的程序员的工匠精神。 摘自:程序员到底是一个什么职业? (尾) 现在自己能听见进去一些原来听不去的话了。我不认为自己是被同化了,也许是心中少了些恶意。 状态不错,继续前进。 – EOF –

August 31, 2016 · 1 min · 59 words · Me

LeetCode Number of 1 Bits 191

191. Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11’ has binary representation 00000000000000000000000000001011, so the function should return 3. 大体意思 写一个函数,输入一个无符号整数,返回其中值为 1 的比特位的个数(这个值也被称为数字汉明重量) 自己的思路 循环判断最后一位是否是 1 public int hammingWeight(int n) { int result = 0; while (n != 0) { if ((n & 1) == 1) { result++; } n = n >> 1; } return result; } 在 Submit Solution ...

August 31, 2016 · 2 min · 235 words · Me

LeetCode Happy Number 202

202. Happy Number Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers. ...

August 29, 2016 · 1 min · 209 words · Me

LeetCode Roman to Integer 13

13. Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. wikipedia-罗马数字 罗马数字共有 7 个,即 I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和 M(1000)。按照下述的规则可以表示任意正整数。需要注意的是罗马数字中没有“0”,与进位制无关。一般认为罗马数字只用来记数,而不作演算。 重复数次:一个罗马数字重复几次,就表示这个数的几倍。 右加左减: 在较大的罗马数字的右边记上较小的罗马数字,表示大数字加小数字。 在较大的罗马数字的左边记上较小的罗马数字,表示大数字减小数字。 左减的数字有限制,仅限于 I、X、C。比如 45 不可以写成 VL,只能是 XLV 但是,左减时不可跨越一个位值。比如,99 不可以用 IC(100-1)表示,而是用 XCIX([100-10]+[10-1])表示。(等同于阿拉伯数字每位数字分别表示。) 左减数字必须为一位,比如 8 写成 VIII,而非 IIX。 右加数字不可连续超过三位,比如 14 写成 XIV,而非 XIIII。(见下方“数码限制”一项。) 加线乘千: 在罗马数字的上方加上一条横线或者加上下标的 Ⅿ,表示将这个数乘以 1000,即是原数的 1000 倍。 同理,如果上方有两条横线,即是原数的 1000000(1000^{{2}})倍。 数码限制: 同一数码最多只能连续出现三次,如 40 不可表示为 XXXX,而要表示为 XL。 例外:由于 IV 是古罗马神话主神朱庇特(即 IVPITER,古罗马字母里没有 J 和 U)的首字,因此有时用 IIII 代替 IV。 自己的解法 做一个数组对照的字典,遵守此条规定:在较大的罗马数字的左边记上较小的罗马数字,表示大数字减小数字。 ...

August 25, 2016 · 1 min · 160 words · Me

LeetCode Majority Element 169

169. Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than [ n/2 ] times. You may assume that the array is non-empty and the majority element always exist in the array. 题目大意 给定一个数组,找这个数组中的主元素,主元素是元素出现次数大于⌊ n/2 ⌋的元素。 假设给定的数组非空,主元素都存在。 自己的解法 将数组进行排序,根据题意,那么中间的这个数就是 majority element public int majorityElement(int[] nums) { Arrays.sort(nums); return nums[nums.length / 2]; } 别人的解法 【LeetCode-面试算法经典-Java 实现】【169-Majority Element(主元素)】 ...

August 24, 2016 · 1 min · 192 words · Me

LeetCode First Unique Character in a String 387

387. First Unique Character in a String Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may assume the string contain only lowercase letters. 自己的解法 开始觉的遍历 char[] 然后判断在 String 的首位置和末位置,若一样就返回索引。呃,感觉有点偷鸡 public int firstUniqChar(String s) { for (int i = 0; i < s.length(); i++) { if (s.indexOf(s.charAt(i)) == s.lastIndexOf(s.charAt(i))) { return i; } } return -1; } 查了下别人的,又是 new int[26] ...

August 23, 2016 · 1 min · 133 words · Me