
矩阵 (matrix)
文章平均质量分 78
beiyetengqing
http://blog.youkuaiyun.com/beiyeqingteng 的镜像站
展开
-
Fibonacci Number (斐波那契数列)
问题: F0 = 0 F1 = 1 Fn = Fn − 1 + Fn − 2 求Fn Fibonacci数列是一个非常经典的用递归解决的问题。递归方法如下: public int F(int n) { if (n == 0) return 0; else if (n == 1) return 1; else return F(n - 1) + F(n - 2)原创 2012-08-12 05:32:14 · 1753 阅读 · 0 评论 -
Group of 1s in a Matrix
Given a matrix with 1s and 0s, please find the number of groups of 1s. A group is defined by horizontally or vertically adjacent 1s. For example, there are four groups of 1s in figure below. Anal原创 2013-02-24 04:48:33 · 564 阅读 · 0 评论 -
Trie + recursion + pruning to implement Boggle
If you want to know what Boggle is, please wiki or google it. Or refer to http://goo.gl/GythQ In this implementation, we need to use a dictionary. Go to http://goo.gl/vaq4Z to download it and as it原创 2013-03-18 04:00:10 · 1432 阅读 · 0 评论 -
rotate matrix
Given an image represented by a matrix, write a method to rotate the image by 90 degrees. Can you do this in place? static void rotateClockwise(int[][] matrix) { int length = matrix.length - 1; for原创 2013-02-26 12:18:29 · 1294 阅读 · 0 评论 -
O变X
给你一个n * n 的二维char数组 内部存的是 'X' 和 'O',形式如下 X X X X X X O O O X X X O O X X X X O X X O X X X 编写一个函数将被'X'包围的'O'统统变成'X'。 比如下标为 (1,1) (1,2) (1,3) (2,2) (2,3) (3,3)的'O'需要被变成'X',而下标原创 2013-02-24 12:45:11 · 819 阅读 · 0 评论 -
Word Search
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2013-01-18 08:37:20 · 921 阅读 · 1 评论 -
Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. public class Solution { public int maximalRectangle(char[][] matrix) {原创 2013-01-29 04:11:02 · 1146 阅读 · 0 评论 -
Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer o原创 2013-01-05 09:40:02 · 820 阅读 · 0 评论 -
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. public class Solution { public void setZeroes(int[][] matrix) { int[] row = new int[matri原创 2012-12-12 06:20:44 · 1036 阅读 · 0 评论 -
Minimum Path Sum
Question: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either d原创 2012-12-14 14:17:27 · 1192 阅读 · 0 评论 -
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [原创 2012-12-26 13:56:37 · 15463 阅读 · 0 评论 -
Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ],原创 2012-12-12 04:36:14 · 2228 阅读 · 0 评论 -
顺时针打印矩阵 (JAVA实现)
问题: 给定一个矩阵,从外向内顺时针打印矩阵中的每一个数字。 例如:给定矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 输出应该为:{1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10} 分析: 问题的本质其实就是打印一原创 2012-07-28 05:55:42 · 5008 阅读 · 0 评论 -
最大子矩阵和
前言: 今天花了很长时间,看了无数人写的帖子,但是几乎没有人把这个问题一下子说得很清楚,所以,我把这个问题按照自己的思路写出来,希望能够把这个问题讲清楚。 问题: 求一个M*N的矩阵的最大子矩阵和。 比如在如下这个矩阵中: 0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 -2 拥有最大和的子矩阵为: 9 2 -4 1 -1 8原创 2012-08-27 07:48:07 · 716 阅读 · 0 评论 -
Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside原创 2016-01-31 00:26:08 · 1511 阅读 · 1 评论