Skip to content

Commit bd3096c

Browse files
committed
Solution
1 parent 7f657dd commit bd3096c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.Rhistory

cachematrix.R

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

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
s <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
s <<- NULL
11+
}
12+
get <- function() {
13+
x
14+
}
15+
setSolve <- function(solve) {
16+
s <<- solve
17+
}
18+
getSolve <- function() {
19+
s
20+
}
21+
list(set = set, get = get, setSolve = setSolve, getSolve = getSolve)
822
}
923

1024

1125
## Write a short comment describing this function
1226

1327
cacheSolve <- function(x, ...) {
1428
## Return a matrix that is the inverse of 'x'
29+
s <- x$getSolve()
30+
if(!is.null(s)) {
31+
message("getting cached data")
32+
return(s)
33+
}
34+
data <- x$get()
35+
s <- solve(data, ...)
36+
x$setSolve(s)
37+
s
1538
}

0 commit comments

Comments
 (0)