- 博客(120)
- 收藏
- 关注
原创 数据类型转换
数据类型转换转换为 boolean false: false, 0, 0.0, "", "0", 空数组, 空对象, NULL, 未赋值变量 true: 其他转换为integer(32位最大值约为20亿) 从 boolean 转换:false 产生 0, true 产生 1; 从 float 转换:向下取整。如果超出了整数范围,则结果为未定义的整型; Warning 绝不要将未知的分数
2017-05-18 19:11:39
253
原创 empty
函数说明 实际执行的是源码中的 i_zend_is_true 函数/** * 使用一个字符串分割另一个字符串 * @param mixed $val 变量或表达式 * @return bool */empty ( $val )实现流程判断参数 IS_NULL: true IS_LONG, IS_BOOL, IS_RESOURCE: 可以理解为 int,为 0 时返回 true
2017-05-08 16:14:44
431
原创 explode
函数说明 array explode ( string $delimiter, string $string, [, int $limit ] )实现流程判断参数 $limit 默认为 PHP_INT_MAX 判断分隔符是否为空,如果为空返回 false判断字符串长度,如果字符串为空且 $limit >= 0,返回一个包含空字符串的数组执行逻辑 根据 $limit 值执行不同逻辑 $
2017-04-27 18:03:33
566
原创 193. Valid Phone Numbers#1
题目摘要 从文件里筛选出电话号码,电话号码有两种格式 (xxx) xxx-xxxx 和 xxx-xxx-xxxx。假设每行头尾都没有空格。解法注意可问问题原题 Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print a
2017-04-21 17:46:12
310
原创 195. Tenth Line#1
题目摘要 答应文件第10行解法 1. 2. 注意 1. 如果文件没有10行,输出什么?可问问题原题 How would you print just the 10th line of a file?For example, assume that file.txt has the following content: Line 1 Line 2 Line 3 Lin
2017-04-21 17:34:57
249
原创 184. Department Highest Salary#1
题目摘要 选出每栋Department中薪水最高的人(每栋楼不知一个)解法 Solution1# Write your MySQL query statement belowSELECT d.Name AS Department, e.Name As Employee, e.SalaryFrom Employee AS eINNER JOIN ( SELECT max(Salary
2017-04-12 09:30:25
263
原创 180. Consecutive Numbers(Done)
题目摘要 写一个SQL查询,用来寻找所有连续出现三次以上的Num Id Num 1 1 2 1 3 1 4 2 5 1 6 2 7 2例如,给定如上Logs表,返回1解法# Write your MySQL query statement belowSELECT distinct(l1.Num) AS ConsecutiveNu
2017-03-27 19:45:18
310
原创 434. Number of Segments in a String#1
Solution#1public class Solution { public int countSegments(String s) { if (s == null || s == 0) return 0; char[] c = s.toCharArray(); int i = 0; int count = 0;
2017-03-20 21:56:09
155
原创 541. Reverse String II#1
Solutionpublic class Solution { public String reverseStr(String s, int k) { if (s == null || s.length() == 0) return s; char[] c = s.toCharArray(); int times = c
2017-03-20 14:02:00
305
原创 344. Reverse String#1
Solution#1public class Solution { public String reverseString(String s) { char[] ca = s.toCharArray(); int l = 0; int r = ca.length - 1; char tmp; while (l <
2017-03-20 10:49:28
188
原创 122. Best Time to Buy and Sell Stock II
题目摘要 给定一个数组,第i个元素代表第i天的股票价格。 你可以随意交易,但是买进之前必须先卖出,求出最大利润解法 1. 如果第i个元素大于第i - 1个元素,将差价加到总利润上注意可问问题原题 Say you have an array for which the ithi^th element is the price of a given stock on day ii.Design
2017-03-08 16:34:30
199
原创 122. Best Time to Buy and Sell Stock II(Done)
Solution#1public class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) return 0; int profit = 0; for (int i = 1; i < pr
2017-03-08 16:28:07
209
原创 53. Maximum Subarray#1
Solution#1public class Solution { public int maxSubArray(int[] nums) { if (nums == null || nums.length == 0) return 0; int index = 0; int sum = 0; int max = Integer.M
2017-03-08 10:10:47
175
原创 476. Number Complement#2
Solution#1public class Solution { public int findComplement(int num) { int tmp = num; int count = 0; while (tmp != 0) { tmp = tmp >> 1; count++;
2017-03-07 21:47:52
174
原创 191. Number of 1 Bits
题目摘要 计算一个32位无符号整数的汉明距离解法 1. n = n & (n - 1); count++ 2. count= count+ (n & 1); n = n>>>1;注意 1. >>>无符号位右移(补零),>>右移可问问题原题 Write a function that takes an unsigned integer and returns the number of ’1
2017-03-07 21:13:38
205
原创 191. Number of 1 Bits#1(Done)
Solution#1(2ms)public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int count = 0; while (n != 0) { n = n & (n - 1);
2017-03-07 21:11:00
176
原创 268. Missing Number
题目摘要 给定一个数组,包含从0, 1, 2, ..., nn个唯一数字,从数组中找到缺少的那个。 例如, nums = [0, 1, 3],返回2。解法 1. 计算0到n的总和account = (0 + n) * (n + 1) / 2,计算数组总和sum,返回account - sum 2. 异或所有的索引和数据,返回注意 1. 注意第一种解法中计算account是n与length
2017-03-07 17:32:56
168
原创 35. Search Insert Position
题目摘要 给定一个有序数组和一个目标值,从数组里面找出目标值的位置。如果找不到,返回它插入的位置。解法 1. 查找先想到二分法,此处需要改良二分查找法。 2. 具体思想为二分,如果目标值在区间外,或者找到目标值,则可以确定目标位置。如在区间右边,返回end + 1;如在区间左边,返回start 2. 使用二分法时,应当防止中值溢出,用mid = left + (right - left) /
2017-03-02 21:44:18
167
原创 35. Search Insert Position#1(Done)
Solution#2public class Solution { public int searchInsert(int[] nums, int target) { if (nums == null && nums.length == 0) return 0; return searchInsert(nums, target, 0, nums.length -
2017-03-02 21:36:57
179
原创 501. Find Mode in Binary Search Tree#2
Solution#1 Problem#1 1. 没什么想法 2. int不能为null,但是Integer可以 3. Integer初始化是考虑是否置null
2017-03-02 19:39:02
229
原创 268. Missing Number#1(Done)
Solution#2public class Solution { public int missingNumber(int[] nums) { int i = 0; int result = 0; while (i < nums.length) { result = result ^ i ^ nums[i];
2017-03-02 17:04:25
231
原创 56. Merge Intervals
题目摘要 给定一组区间集合,返回合并后的区间。 例如, 给定[1,3],[2,6],[8,10],[15,18], 返回[1,6],[8,10],[15,18].解法 1. 将给定列表按区间开头进行排序(可以用匿名内部类new Comparator实现继承Comparator的效果),然后根据区间结尾的情况合并 2. 把区间开头和结尾分别存到一个数组里,分别排序,然后合并区间(这一步步骤
2017-03-02 15:22:51
170
原创 178. Rank Scores#1
Solution#1# Write your MySQL query statement belowSELECT Score, (SELECT COUNT(DISTINCT Score) FROM Scores WHERE S.Score <= Score) Rank From Scores S ORDER BY Score DESCSolution#2# Write yo
2017-03-01 21:53:13
218
原创 196. Delete Duplicate Emails#1
Solution#1# Write your MySQL query statement belowDELETE p1FROM Person p1, Person p2 WHERE p1.Email = p2.EmailAND p1.Id > p2.IdSolution#2(更快)# Write your MySQL query statement belowDELETE FROM Pe
2017-03-01 21:25:44
175
原创 196. Delete Duplicate Emails#1
Solution#1# Write your MySQL query statement belowDELETE p1FROM Person p1, Person p2 WHERE p1.Email = p2.EmailAND p1.Id > p2.IdSolution#2(更快)# Write your MySQL query statement belowDELETE FROM Pe
2017-03-01 21:25:32
146
原创 196. Delete Duplicate Emails#1
Solution#1# Write your MySQL query statement belowDELETE p1FROM Person p1, Person p2 WHERE p1.Email = p2.EmailAND p1.Id > p2.IdSolution#2(更快)# Write your MySQL query statement belowDELETE FROM Pe
2017-03-01 21:25:29
343
原创 176. Second Highest Salary#1
Solutin#1# Write your MySQL query statement belowSELECT MAX(Salary) AS SecondHighestSalaryFROM EmployeeWHERE Salary < (SELECT MAX(Salary) FROM Employee)#Using max() will return a NULL #if the value
2017-03-01 20:32:53
183
原创 197. Rising Temperature#1
Solution#1# Write your MySQL query statement belowSELECT T.Id FROM Weather AS T INNER JOIN Weather AS Y ON T.Date = Y.Date + interval 1 dayAND T.Temperature > Y.Temperature;Problem#1 1. 题目没仔细思考,Id
2017-03-01 20:22:57
239
原创 175. Combine Two Tables
Solution#1# Write your MySQL query statement belowSELECT Name AS Customers FROM Customers WHERE Id NOT IN(SELECT CustomerId FROM Orders)
2017-03-01 17:35:57
177
原创 175. Combine Two Tables
Solution#1# Write your MySQL query statement belowSELECT P.FirstName, P.LastName, A.City, A.State From Person AS P LEFT JOIN Address AS A ON P.PersonId = A.PersonId
2017-03-01 11:33:51
164
原创 181 Employees Earning More Than Their Managers
Solution#1# Write your MySQL query statement belowSELECT E.Name AS Employee FROM Employee AS E INNER JOIN Employee AS M ON E.ManagerId = M.Id WHERE E.Salary > M.SalaryProblem 1. 注意查询结果的表名
2017-03-01 11:32:55
561
原创 182. Duplicate Emails#2
Solutin#1SELECT Email FROM (SELECT Email, COUNT(Email) AS Cnt FROM Person GROUP BY Email) T WHERE Cnt > 1Solutin#2()SELECT Email FROM Person GROUP BY Email HAVING COUNT(Email) > 1Problem 1. Mysql:Wi
2017-03-01 11:00:40
187
原创 56. Merge Intervals#2(Done)
Solution#1Problem#1 1.不用类继承的方法不会写Comparator,这个概念还要搞懂 2.写得不熟练 3.List<Interval> result = new LinkedList<Interval>();比List<Interval> result = new LinkedList<>();快 4.第二种方法
2017-03-01 10:37:02
232
原创 405. Convert a Number to Hexadecimal#2
Solution#1 Problem#1试着用位操作去解决,而不是通过触发
2017-01-08 22:02:28
168
原创 415. Add Strings#1(Done)
Solution#1public class Solution { public String addStrings(String num1, String num2) { if (num1.equals("0")) return num2; if (num2.equals("0")) return num1;
2017-01-08 21:22:54
180
原创 401. Binary Watch#1(Done)
Solution#1public class Solution { public List<String> readBinaryWatch(int num) { if (num < 0 || num > 10) throw new IllegalArgumentException("the argument for readBinaryWatch is
2017-01-08 16:28:58
291
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人