摘要:
class MovingAverage { Queue<Integer> queue = new LinkedList<>(); int size = 0; double sum=0; public MovingAverage(int size) { this.size = size; } publ
阅读全文
posted @ 2022-04-09 05:25
阳光明媚的菲越
阅读(22)
推荐(0)
摘要:
class Solution { public boolean isPalindrome(String s) { s= s.toLowerCase(); int i=0, j=s.length()-1; while(i<j){ char a = s.charAt(i); char b = s.cha
阅读全文
posted @ 2022-04-09 04:32
阳光明媚的菲越
阅读(16)
推荐(0)
摘要:
We use two points to point to two successive nodes, we call them "pre" and "cur" We need to consider 3 situation need to be considered: 1. the inserte
阅读全文
posted @ 2022-04-09 02:34
阳光明媚的菲越
阅读(24)
推荐(0)
摘要:
The most important things to solve this problem are: recognizing this is a graph problem. Select a correct data structure to store the graph: Map<Stri
阅读全文
posted @ 2022-04-08 03:59
阳光明媚的菲越
阅读(18)
推荐(0)
摘要:
My PriorityQueue Solution: class Solution { public int[][] merge(int[][] intervals) { PriorityQueue<int[]> queue = new PriorityQueue<>((a,b)->a[0]-b[0
阅读全文
posted @ 2022-04-07 06:33
阳光明媚的菲越
阅读(25)
推荐(0)
摘要:
Just use BFS to solve this problem: 1. put the s to queue 2. if s is not a valid string, then remove a '(' or ')', and then put to the queue. 3. once
阅读全文
posted @ 2022-04-07 02:42
阳光明媚的菲越
阅读(34)
推荐(0)
摘要:
For this problem, we need to consider the following cases: +23 - valid 23+5 - invalid 9e - invalid e6 - invalid 23e+5 - valid 9.6e2 - valid 9e6.2 - in
阅读全文
posted @ 2022-04-06 13:08
阳光明媚的菲越
阅读(8)
推荐(0)
摘要:
My first solution - using ArrayList: class MyCircularDeque { List<Integer> list = new ArrayList<>(); int k ; public MyCircularDeque(int k) { this.k =
阅读全文
posted @ 2022-03-31 06:49
阳光明媚的菲越
阅读(21)
推荐(0)
摘要:
My first solution: class Solution { public int[] plusOne(int[] digits) { int n = digits.length; int carry = 1; for(int i=n-1;i>=0;i--){ int digit = di
阅读全文
posted @ 2022-03-31 04:13
阳光明媚的菲越
阅读(276)
推荐(0)
摘要:
Using binary search, time complexity: O(log(x)) class Solution { public int mySqrt(int x) { int l=1, r =x; while(l<r-1){ int mid=l+(r-l)/2; int temp =
阅读全文
posted @ 2022-03-31 01:01
阳光明媚的菲越
阅读(30)
推荐(0)