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
public int findUnsortedSubarray(int[] A) { | |
int n = A.length, beg = -1, end = -2, min = A[n-1], max = A[0]; | |
for (int i=1;i<n;i++) { | |
max = Math.max(max, A[i]); | |
min = Math.min(min, A[n-1-i]); | |
if (A[i] < max) end = i; | |
if (A[n-1-i] > min) beg = n-1-i; | |
} | |
return end - beg + 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
public int lengthOfLongestSubstring(String s) { | |
HashMap<Character,Integer> set = new HashMap<>(); | |
int max = 0;int j=0; | |
for(int i=0;i<s.length();i++){ | |
char c = s.charAt(i); | |
if(set.containsKey(c)){ | |
// as we dont delete history, we dont | |
// want to jump back to index in a substring that is dead | |
j = Math.max(j, set.get(c)+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
function lock(boolean *lock) { | |
while (test_and_set(lock) == 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
int add_no_arithm(int a, int b) { | |
if (b == 0) return a; | |
int sum = a ^ b; // add without carrying | |
int carry = (a & b) << 1; // carry, but don’t add | |
return add_no_arithm(sum, carry); // recurse | |
} |
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
Predicate<Person> isAnAdult = person -> person.getAge() >= 18; | |
List<Person> people = getAllPeople(); | |
Integer nrOfAdults = people.stream() .filter(isAnAdult).count(); |
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
Function<String, Predicate<Ticket>> ticketFor = event -> ticket -> event.equals(ticket.getName()); | |
List<Ticket> tickets = getAllTickets(); | |
Integer soldTicketsForCoolEvent = tickets.stream() | |
.filter(ticketFor.apply("CoolEvent")).count(); | |
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
- kind: ReplicationController | |
apiVersion: v1 | |
metadata: | |
name: bad-frontend | |
labels: | |
name: bad-frontend | |
spec: | |
replicas: 1 | |
selector: | |
name: bad-frontend |
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
<ScrollView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<TextView | |
android:id="@+id/tv_weather_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:padding="16dp" | |
android:textSize="20sp" /> |
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
/* | |
* Iterate through the array and append the Strings to the TextView. The reason why we add | |
* the "\n\n\n" after the String is to give visual separation between each String in the | |
* TextView. Later, we'll learn about a better way to display lists of data. | |
*/ | |
for (String toyName : toyNames) { | |
mToysListTextView.append(toyName + "\n\n\n"); | |
} |
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
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// other code to setup the activity | |
} | |
// other code | |
} |
OlderNewer