Skip to content

Commit 5afbd1f

Browse files
committed
Init.
1 parent 7f657dd commit 5afbd1f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cachematrix.R

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
m <- NULL
8+
set <- function(y) {
9+
x <<- y;
10+
m <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inverse) m <<- inverse
14+
getinverse <- function() m
15+
list(set = set, get = get, getinverse = getinverse, setinverse = setinverse)
816
}
917

1018

1119
## Write a short comment describing this function
1220

1321
cacheSolve <- function(x, ...) {
1422
## Return a matrix that is the inverse of 'x'
23+
m <- x$getinverse()
24+
if (!is.null(m)) {
25+
message("hit")
26+
return(m)
27+
}
28+
29+
data <- x$get()
30+
m <- solve(data)
31+
x$setinverse(m)
32+
m
1533
}

0 commit comments

Comments
 (0)