Skip to content

Commit cc228fc

Browse files
committed
add 2d matrix ii and del node
1 parent 84277f5 commit cc228fc

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

delete-node-in-a-linked-list/README.md

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
public class Solution {
10+
public void deleteNode(ListNode node) {
11+
node.val = node.next.val;
12+
node.next = node.next.next;
13+
}
14+
}

delete-node-in-a-linked-list/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: solution
3+
title: Delete Node in a Linked List
4+
date: 2015-07-26 14:42:29+08:00
5+
leetcode_id: 237
6+
---
7+
{% include_relative README.md %}

search-a-2d-matrix-ii/README.md

Whitespace-only changes.

search-a-2d-matrix-ii/Solution.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class Solution {
2+
3+
boolean searchMatrix(int[][] matrix, int stX, int stY, int edX, int edY, int target) {
4+
5+
if (stX >= edX || stY >= edY) return false;
6+
7+
int max = matrix[edX - 1][edY - 1];
8+
int min = matrix[stX][stY];
9+
10+
// min <= target <= max
11+
if (min <= target && target <= max){
12+
13+
int mdX = (stX + edX) / 2;
14+
int mdY = (stY + edY) / 2;
15+
16+
if(matrix[mdX][mdY] == target){
17+
return true;
18+
}
19+
20+
return searchMatrix(matrix, stX, stY, mdX, mdY, target) ||
21+
searchMatrix(matrix, stX, mdY, mdX, edY, target) ||
22+
searchMatrix(matrix, mdX, stY, edX, mdY, target) ||
23+
searchMatrix(matrix, mdX, mdY, edX, edY, target);
24+
}
25+
26+
return false;
27+
}
28+
29+
public boolean searchMatrix(int[][] matrix, int target) {
30+
return searchMatrix(matrix, 0, 0, matrix.length, matrix[0].length, target);
31+
}
32+
}

search-a-2d-matrix-ii/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: solution
3+
title: Search a 2D Matrix II
4+
date: 2015-07-26 14:40:48+08:00
5+
leetcode_id: 240
6+
---
7+
{% include_relative README.md %}

0 commit comments

Comments
 (0)