Skip to content

Commit

Permalink
2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng102e committed Feb 16, 2020
1 parent 6027f4d commit 45d1818
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/Q11.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @author Cheng102e
* @version 1.0
* @date 2020/2/16 14:17
*/
public class Q11 {

public int maxArea(int[] height) {
int left = 0, right = height.length - 1;
int max = 0;
while (left < right) {
max = Math.max(max, (right - left) * Math.min(height[left], height[right]));
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return max;
}

public static void main(String[] args) {
System.out.println("Hello World!");
}
}
25 changes: 25 additions & 0 deletions src/Q215.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.PriorityQueue;

/**
* @author Cheng102e
* @version 1.0
* @date 2020/2/16 12:12
*/
public class Q215 {

public static int findKthLargest(int[] nums, int k) {
PriorityQueue<Integer> heap =
new PriorityQueue<Integer>((n1, n2) -> n1 - n2);
for (int n : nums) {
heap.add(n);
if (heap.size() > k) {
heap.poll();
}
}
return heap.poll();
}

public static void main(String[] args) {
System.out.println("Hello World!");
}
}
22 changes: 22 additions & 0 deletions src/Q344.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @author Cheng102e
* @version 1.0
* @date 2020/2/16 13:05
*/
public class Q344 {

public void reverseString(char[] s) {
int left = 0, right = s.length - 1;
while (left < right) {
char temp = s[left];
s[left] = s[right];
s[right] = temp;
left++;
right--;
}
}

public static void main(String[] args) {
System.out.println("Hello World!");
}
}
37 changes: 37 additions & 0 deletions src/Q345.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @author Cheng102e
* @version 1.0
* @date 2020/2/16 13:05
*/
public class Q345 {

public static boolean find(char c) {
return !(c == 'a' || c == 'o' || c == 'e' || c == 'i' || c == 'u' || c == 'A' || c == 'O'
|| c == 'E' || c == 'I' || c == 'U');
}

public static String reverseVowels(String s) {
char[] arr = s.toCharArray();
int left = 0, right = arr.length - 1;
while (left < right) {
while (left < arr.length && find(arr[left])) {
left++;
}
while (right >= 0 && find(arr[right])) {
right--;
}
if (left >= right) {
break;
}
char temp = arr[right];
arr[right--] = arr[left];
arr[left++] = temp;
}
String result = new String(arr);
return result;
}

public static void main(String[] args) {
System.out.println("Hello World!");
}
}

0 comments on commit 45d1818

Please sign in to comment.