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
| void solve() { | |
| int n, x;//dimnesiune si butonul apasat: x secunde | |
| cin>>n>>x; | |
| int l = 1e5, r = -1; | |
| for(int i = 0; i < n; ++i) { |
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
| //1,3,4,2,2 | |
| [1,2,3,4] | |
| 4/2 = 2 | |
| int findDuplicate(vector<int>_&nums) { | |
| int low = 1; | |
| int high = nums.size() - 1;// 5= 5-1= 4 | |
| [1,2,3,4] |
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
| int findDuplicate(vector<int>_&nums) { | |
| int low = 1; | |
| int high = nums.size() - 1;// 5= 5-1= 4 | |
| [1,2,3,4] | |
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
| bool validMountain(vector<int>& arr) { | |
| int n = arr.size(); | |
| int start = 0; | |
| int end = n - 1; | |
| //urcare |
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 Main { | |
| //Maarriaa | |
| public static int CountDistinctChars(String s) { | |
| Set<Character> set = new HashSet<>();//caracterele vor fi distincte | |
| for(char c : s.toCharArray()) {//m, a, |
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
| class Solution { | |
| public boolean isPalindrome(String s) { | |
| StringBuilder tmp = new StringBuilder(); | |
| //Time Complexity: O(n) | |
| for(char c: s.toCharArray()) { |
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
| import java.io.*; | |
| import java.util.*; | |
| public class Rucsac { | |
| public static void main(String[] args) throws IOException { | |
| BufferedReader fin = new BufferedReader(new FileReader("rucsac.in")); |
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
| Brute-force --->> incerci toate variantele posibile | |
| Backtracking - te intorci daca nu mai poti inainta | |
| Greedy - >alegi mereu cea mai buna decizie locala | |
| - decizii pas cu pas | |
| - nu revii asupra alegerilor |
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
| /* | |
| for(int i = 1; i <= n; ++i) { | |
| for(int j = 1; j <= n; ++j) { | |
| } | |
| } | |
| O(n^2) | |
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
| input: | |
| numar de obiecte, capacitate rucsac | |
| urmatoarele linii: | |
| greutate obiecte, profit obiect | |
| 5 10 | |
| 3 2 | |
| 4 3 |