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
/* | |
Copyright 2013 Google Inc. All Rights Reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
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 AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener; | |
//… | |
mOnAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() { | |
@Override | |
public void onAudioFocusChange(int focusChange) { | |
switch (focusChange) { | |
case AudioManager.AUDIOFOCUS_GAIN: | |
Log.i(TAG, "AUDIOFOCUS_GAIN"); | |
// Set volume level to desired levels |
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
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
public class DetectAndroidTV : MonoBehaviour { | |
public Text detectionText; | |
// Use this for initialization | |
void Start () { |
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 roundm(n, m) return math.floor(((n + m - 1)/m))*m end | |
-- Now we can change the returned value from getRandomPointInCircle to: | |
function getRandomPointInCircle(radius) | |
local t = 2*math.pi*math.random() | |
local u = math.random()+math.random() | |
local r = nil | |
if u > 1 then r = 2-u else r = u end | |
return roundm(radius*r*math.cos(t), tile_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
static void quicksort(int[] a, int low, int high) { | |
if(low<high){ | |
int p = partition(a,low,high); | |
quicksort(a,low,p-1); | |
quicksort(a,p+1,high); | |
} | |
} | |
static int partition(int[] a, int low, int high) { | |
int p = a[high]; |
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
static void insertSort(int[] a) { | |
for(int i=1;i<a.Length;++i) { | |
int x = a[i]; | |
int j = i - 1; | |
while(j>=0 && a[j]>x){ | |
a[j+1]=a[j]; | |
--j; | |
} | |
a[j+1]=x; | |
} |
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
/** | |
Given an array of integers, sort the array into a wave like array and return it, | |
In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5..... | |
Example | |
Given [1, 2, 3, 4] | |
One possible answer : [2, 1, 4, 3] | |
Another possible answer : [4, 1, 3, 2] |
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
/*** | |
Given an array of size n, find the majority element. The majority element is the element that appears more than floor(n/2) times. | |
You may assume that the array is non-empty and the majority element always exist in the array. | |
***/ | |
public static int majorityElement(final List<Integer> a) { | |
HashMap<Integer,Integer> count = new HashMap<Integer,Integer>(); | |
Integer largestKey = 0; |
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
/** | |
Reverse bits of an 32 bit unsigned integer | |
Example 1: | |
x = 0, | |
00000000000000000000000000000000 | |
=> 00000000000000000000000000000000 | |
return 0 |
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
/** | |
Given an array A of integers and another non negative integer k, find if there exists 2 indices i and j such that A[i] - A[j] = k, i != j. | |
Example : | |
Input : | |
A : [1 5 3] | |
k : 2 | |
Output : |