Created
September 8, 2020 21:28
-
-
Save so77id/b4d6960f45d4d81b13a91a7b6f6dadd4 to your computer and use it in GitHub Desktop.
Sol ev 1 - intento 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 static int bin2dec(SinglyLinkedListNode head) { | |
SinglyLinkedListNode tmp = head; | |
int count, num; | |
count = num = 0; | |
while(tmp != null) { | |
count++; | |
tmp = tmp.next; | |
} | |
tmp = head; | |
for(; count > 0; count--) { | |
num += tmp.data * Math.pow(2, count-1); | |
tmp = tmp.next; | |
} | |
return num; | |
} |
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 static List<Integer> ForecastTermometer(List<Integer> T) { | |
List<Integer> ans = new ArrayList<Integer>(); | |
Stack<Integer> stack = new Stack(); | |
for (int i = T.size() - 1; i >= 0; --i) { | |
while (!stack.isEmpty() && T.get(i) >= T.get(stack.peek())) stack.pop(); | |
ans.add(stack.isEmpty() ? 0 : stack.peek() - i); | |
stack.push(i); | |
} | |
Collections.reverse(ans); | |
return ans; | |
} |
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 static SinglyLinkedListNode MergeTwoOrderedList(SinglyLinkedListNode l1, SinglyLinkedListNode l2) { | |
if (l1 == null) { | |
return l2; | |
} | |
else if (l2 == null) { | |
return l1; | |
} | |
else if (l1.data < l2.data) { | |
l1.next = MergeTwoOrderedList(l1.next, l2); | |
return l1; | |
} | |
else { | |
l2.next = MergeTwoOrderedList(l1, l2.next); | |
return l2; | |
} | |
} |
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 static String PairRemove(String s) { | |
Stack<Character> stack = new Stack<Character>(); | |
for(char c:s.toCharArray()) { | |
if(!stack.empty()) { | |
if(stack.peek() == c) stack.pop(); | |
else stack.push(c); | |
} else stack.push(c); | |
} | |
String sol = ""; | |
while(!stack.empty()) { | |
sol = stack.peek() + sol; | |
stack.pop(); | |
} | |
return sol; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment