This file contains hidden or 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
| public class QuickSelect { | |
| public int quickSelect(int[] arr, int k) { | |
| return quickSelect(arr, k, 0, arr.length - 1); | |
| } | |
| private int quickSelect(int[] arr, int k, int start, int end){ | |
| if (k > arr.length) throw new IllegalArgumentException(); | |
| if (arr.length == 0 || arr == null) return Integer.MIN_VALUE; | |
| var pivotIndex = randomlySelect(arr); |
This file contains hidden or 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
| package com.allenhuang; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| public class DeterministicSelect { | |
| // store the median of each group | |
| private ArrayList<Integer> medians = new ArrayList<>(); | |
| public int select(int[] arr, int k) { |
This file contains hidden or 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
| package com.allenhuang; | |
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| public class Graph { | |
| private Map<String, Node> nodes = new HashMap<>(); | |
| private Map<Node, List<Node>> adjacencyList = new HashMap<>(); |
This file contains hidden or 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
| package com.allenhuang; | |
| import java.util.*; | |
| public class Graph2 { | |
| private Map<Node,Integer> map = new HashMap(); | |
| private List<LinkedList<Node>> adjacencyList = new ArrayList(); | |
| private int index = 0; | |
| private class Node { |
This file contains hidden or 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
| package com.allenhuang; | |
| import java.util.*; | |
| public class Graph { | |
| private Map<String, Node> nodes = new HashMap<>(); | |
| private Map<Node, List<Node>> adjacencyList = new HashMap<>(); | |
| private class Node { | |
| private String label; |
This file contains hidden or 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
| package com.allenhuang; | |
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| public class WeightedGraph { | |
| private Map<String, Node> nodes = new HashMap<>(); | |
| private Map<Node, List<Edge>> adjacencyList = new HashMap<>(); |
This file contains hidden or 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
| text = [] | |
| like = [] | |
| date = [] | |
| reply_to = [] | |
| text = [] | |
| name = [] | |
| def is_break_point(astring:str): | |
| if 'React' in astring: | |
| return True |
This file contains hidden or 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 main(): | |
| df['polarity'] = df['text_prep'].parallel_apply(lambda x: round(TextBlob(x).polarity,3)) | |
| df['subjectivity'] = df['text_prep'].parallel_apply(lambda x: round(TextBlob(x).subjectivity,3)) | |
| df = subjectivity_labeling(df) | |
| df = polarity_labeling(df) | |
| # labeling subjectivity | |
| def subjectivity_labeling(df,threshold=0.5): | |
| if threshold == 0.5: | |
| df.loc[df.subjectivity > 0.5,"subjectivity_label"] = 'subjective' |