This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Boyer Moore | |
# Python3 Program for Bad Character Heuristic | |
# of Boyer Moore String Matching Algorithm | |
# https://www.geeksforgeeks.org/boyer-moore-algorithm-for-pattern-searching/ | |
NO_OF_CHARS = 256 | |
def badCharHeuristic(string, size): | |
''' | |
The preprocessing function for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_file_line_by_line(filename, pattern): | |
if not filename.endswith('.kt') and not filename.endswith('.java') and not filename.endswith('.xml'): | |
print(f' Invalid file. filename is {filename}') | |
return | |
try: | |
with open(filename, 'r', encoding='UTF-8') as file: | |
while (line := file.readline().rstrip()): | |
print(line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
private static final int[][] directions = new int[][] { | |
{0, 1}, | |
{1, 0}, | |
{-1, 0}, | |
{0, -1} | |
}; | |
public int shortestPath(int[][] grid, int k) { | |
int TARGET_ROW = grid.length -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode.com/problems/permutations/ | |
class Solution { | |
public List<List<Integer>> permute(int[] nums) { | |
List<List<Integer>> ans = new ArrayList(); | |
if(nums == null || nums.length == 0) return ans; | |
ans.add(new ArrayList()); | |
for(int i = 0; i < nums.length; i++) { | |
int size = ans.size(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class StringPermutation { | |
// obdbcaf | |
public static boolean findPermutation(String str, String pattern) { | |
int left = 0; | |
int patternLength = pattern.length(); | |
HashMap<Character, Integer> map = new HashMap(); | |
for(int i = 0; i < pattern.length(); i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
private List<List<Integer>> result = new ArrayList(); | |
public List<List<Integer>> fourSum(int[] nums, int target) { | |
Arrays.sort(nums); | |
List<Integer> previousNum = new ArrayList(); | |
kSum(previousNum, nums, 4, 0, target); | |
return result; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity() { | |
@Inject | |
lateinit var emailSender: EmailSender | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.main_activity) | |
println("From $this EmailSender is $emailSender") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private EmailSender getEmailSender() { | |
Object local = emailSender; | |
if (local instanceof MemoizedSentinel) { | |
synchronized (local) { | |
local = emailSender; | |
if (local instanceof MemoizedSentinel) { | |
local = new EmailSender(); | |
emailSender = DoubleCheck.reentrantCheck(emailSender, local); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainFragment: Fragment(){ | |
... | |
... | |
... | |
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
viewModel._onActivityCreated.call() | |
} | |
... | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MainThread | |
public static <X, Y> LiveData<Y> map(@NonNull LiveData<X> source, | |
@NonNull final Function<X, Y> func) { | |
final MediatorLiveData<Y> result = new MediatorLiveData<>(); | |
result.addSource(source, new Observer<X>() { | |
@Override | |
public void onChanged(@Nullable X x) { | |
result.setValue(func.apply(x)); | |
} | |
}); |
NewerOlder