Skip to content

Commit

Permalink
Merge pull request #2 from ParkJangSu/green_study
Browse files Browse the repository at this point in the history
Added java solution for 14 / python solution for 2420
  • Loading branch information
green-study committed Sep 30, 2022
2 parents f0852fb + 05d5cce commit 5b9b0f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
7 changes: 4 additions & 3 deletions java/014_Longest_Common_Prefix.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//014_Longest_Common_Prefix.java
class Solution {
public String longestCommonPrefix(String[] strs) {
String result ="";
String temp = "";
int c = 0;
int c = 0; //move first point
boolean check = true;
while(true){
for(int i = 0; i<strs.length; i++){
for(int i = 0; i<strs.length; i++){ //move second point
if(c>=strs[i].length()){
check = false;
break;
}
if(i==0){
if(i==0){ //temp -> check same Character
temp = Character.toString(strs[0].charAt(c));
}
if(!temp.equals(Character.toString(strs[i].charAt(c)))){
Expand Down
38 changes: 38 additions & 0 deletions python/2420_Find_All_Good_Indices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#2420_Find_All_Good_Indices.py
class Solution:
def goodIndices(self, nums: List[int], k: int) -> List[int]:
# posi : count the increasing idxes
# nega : count the decreasing idxes
posi, nega = [0], [0]

for i in range(1, len(nums)):
diff = nums[i] - nums[i - 1]

posi.append(posi[i - 1])
nega.append(nega[i - 1])

# if diff show positive or negative
# then the value will updated
if diff > 0:
posi[i] += 1
elif diff < 0:
nega[i] += 1

# ans : count the idxes that
# before k element is non increasing
# after k element is non decreasing
ans = []
for i in range(k, len(nums) - k):
if i + k >= len(nums):
break

# check the condition with
# for after, nega[i + 1], nega[i + k] is the two to check
# for brfore, posi[i - 1], posi[i - k] is the two to check
if nega[i + k] - nega[i + 1] > 0:
continue
if posi[i - 1] - posi[i - k] > 0:
continue

ans.append(i)
return ans

0 comments on commit 5b9b0f9

Please sign in to comment.