433. Number of Islands【LintCode java】】的更多相关文章

Description Given a boolean 2D matrix, 0 is represented as the sea, 1 is represented as the island. If two 1 is adjacent, we consider them in the same island. We only consider up/down/left/right adjacent. Find the number of islands. Example Given gra…
Description Given two binary strings, return their sum (also a binary string). Example a = 11 b = 1 Return 100 解题:二进制相加.我的思路是,先转成StringBuilder对象(reverse方法比较好用),因为相加是从最后开始,所以先用reverse方法倒转过来.和上一题类似,用carry变量表示进位,0为不进位,1为需要进一位.最后的结果再倒过来.具体细节标注在代码中,代码如下:…
Description Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. Example Given [1,2,3] which represents 123, return [1,2,4]. Give…
Description Given a binary tree, find all paths that sum of the nodes in the path equals to a given number target. A valid path is from root node to any of the leaf nodes. Example Given a binary tree, and target = 5: 1 / \ 2 4 / \ 2 3 return [ [1, 2,…
Description Partition an integers array into odd number first and even number second. Example Given [1, 2, 3, 4], return [1, 3, 2, 4] Challenge Do it in-place. 解题:将一个数组中的奇数和偶数分开,原地分开,不申请额外的空间.思路是,记录好最后一个奇数的后一个位置,也可以理解为偶数中的第一个·.遍历数组,如果当前数组中的元素是偶数,那么什么…
Description Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. Example Linked list is 1->2->3->4, and given node 3, delete the node in place 1->2->4 解题:删除指定的结点.由于java没有delete 或者 fr…
Description There is a building of n floors. If an egg drops from the k th floor or above, it will break. If it's dropped from any floor below, it will not break. You're given two eggs, Find k while minimize the number of drops for the worst case. Re…
Description Given a linked list, swap every two adjacent nodes and return its head. Example Given 1->2->3->4, you should return the list as 2->1->4->3. Challenge Your algorithm should use only constant space. You may not modify the value…
Description Cosine similarity is a measure of similarity between two vectors of an inner product space that measures the cosine of the angle between them. The cosine of 0° is 1, and it is less than 1 for any other angle. See wiki: Cosine Similarity H…
Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. Example The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]"…