Skip to content

Commit 688b5f9

Browse files
add level 1 problems
1 parent 4a8b270 commit 688b5f9

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

deleteAtTail.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// java.util.* and java.util.streams.* have been imported for this problem.
2+
// You don't need any other imports.
3+
4+
public ListNode deleteAtTail(ListNode head) {
5+
if(head == null || head.next == null) return null;
6+
7+
ListNode node = head;
8+
9+
while(node.next.next != null) {
10+
node = node.next;
11+
}
12+
13+
node.next = null;
14+
return head;
15+
}

findMiddleNode.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// java.util.* and java.util.streams.* have been imported for this problem.
2+
// You don't need any other imports.
3+
4+
public ListNode findMiddleNode(ListNode head) {
5+
if(head == null || head.next == null) return head;
6+
7+
ListNode fast = head;
8+
ListNode slow = head;
9+
while(fast.next != null && fast.next.next != null) {
10+
slow = slow.next;
11+
fast = fast.next.next;
12+
}
13+
14+
return slow;
15+
}

flipHorizontalAxis.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// java.util.* and java.util.streams.* have been imported for this problem.
2+
// You don't need any other imports.
3+
4+
public static void flipHorizontalAxis(int[][] matrix) {
5+
int rowLength = matrix.length - 1;
6+
7+
for(int i = 0; i < matrix.length / 2; i++) {
8+
for(int j = 0; j < matrix[i].length; j++) {
9+
int temp = matrix[i][j];
10+
matrix[i][j] = matrix[rowLength - i][j];
11+
matrix[rowLength - i][j] = temp;
12+
}
13+
}
14+
}

isStringPalindrome.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// java.util.* and java.util.streams.* have been imported for this problem.
2+
// You don't need any other imports.
3+
4+
public static boolean isStringPalindrome(String str){
5+
if(str == null || str.length() == 0) return true;
6+
7+
int lastIndex = str.length() - 1;
8+
9+
for(int i = 0; i <= lastIndex / 2; i++) {
10+
11+
char start = str.charAt(i);
12+
char end = str.charAt(lastIndex - i);
13+
if(start != end) {
14+
return false;
15+
}
16+
}
17+
18+
return true;
19+
}

0 commit comments

Comments
 (0)