LeetCode 56 合并区别 Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 关键就是a[1]>=b[0] 也就是array[i-1][1]>=array[i][0] const merge = array => { array.sort((a, b) => a[0] - b[0]) for (let i = 1; i < array.length; i++) { let minLeft = M
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow: F(k
A peak element is an element that is greater than its neighbors. Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index. The array may contain multiple peaks, in that case return the index to any one of the pea
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1].
LeetCode 461. 汉明距离 or LintCode 365. 二进制中有多少个1 题目一:LeetCode 461. 汉明距离 LeetCode 461.明距离(Hamming Distance) 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目.给出两个整数 x 和 y,计算它们之间的汉明距离. 注意 0 ≤ x, y < 2^31. 示例 Java 代码 class Solution { public int hammingDistance(int x, int
1. ArrayList 和 LinkedList 的区别 http://pengcqu.iteye.com/blog/502676 2. How to reverse LinkedList http://www.java2blog.com/2014/07/how-to-reverse-linked-list-in-java.html /** * Definition for ListNode. * public class ListNode { * int val; * ListNode ne
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones. The total number of stones
为了装修新房,你需要加工一些长度为正整数的棒材 sticks. 如果要将长度分别为 X 和 Y 的两根棒材连接在一起,你需要支付 X + Y 的费用. 由于施工需要,你必须将所有棒材连接成一根. 返回你把所有棒材 sticks 连成一根所需要的最低费用.注意你可以任意选择棒材连接的顺序. 1≤sticks.length≤10^4 1≤sticks[i]≤10^4 在线评测地址:https://www.lintcode.com/problem/minimum-cost-to-connect