-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path210704.java
More file actions
101 lines (83 loc) · 2.67 KB
/
Copy path210704.java
File metadata and controls
101 lines (83 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.util.Arrays;
class Solution {
public int solution(int[] prices, int[] discounts) {
int answer = 0;
int idx = discounts.length-1;
Arrays.sort(prices);
Arrays.sort(discounts);
for(int p=prices.length-1; p>=0; p--){
if(idx>=0){
answer += prices[p]*(100-discounts[idx])/100;
idx--;
}
else {
answer += prices[p];
}
}
return answer;
}
}
import java.util.*;
class Solution {
public String[] solution(String s) {
//String[] answer = {};
List<String> answer = new LinkedList<String>();
int leftlow = 0, lefthigh = 0;
int rightlow = s.length()-1, righthigh = s.length()-1;
int now = 0;
while(leftlow<=rightlow){
if(s.substring(leftlow, lefthigh+1).equals(s.substring(rightlow, righthigh+1))){
//System.out.println(s.substring(leftlow, lefthigh+1));
if(leftlow != rightlow){
answer.add(now, s.substring(leftlow, lefthigh+1));
answer.add(answer.size()-now, s.substring(leftlow, lefthigh+1));
now++;
}
else
answer.add(now, s.substring(leftlow, lefthigh+1));
leftlow = lefthigh+1;
lefthigh = leftlow;
righthigh = rightlow-1;
rightlow = righthigh;
}
else{
lefthigh++;
rightlow--;
}
}
return answer.toArray(new String[0]);
}
}
import java.util.*;
public class Solution {
public int solution(String s, String t) {
int result = 0;
Stack<Integer> stack = new Stack<>();
for(int i=0; i<s.length(); i++){
if(stack.empty()){
if(s.charAt(i) == t.charAt(0)){
stack.push(0);
}
else stack.push(-1);
}
else{
if(s.charAt(i) == t.charAt(stack.peek() + 1)){
stack.push(stack.peek()+1);
}
else{
if(s.charAt(i) == t.charAt(0)){
stack.push(0);
}
else stack.push(-1);
}
}
if(stack.peek() == t.length()-1){
for(int j=0; j<t.length(); j++){
stack.pop();
}
result++;
}
}
return result;
}
}