>s>>e;
25 | s-=1;e-=1;
26 | if(s==0)
27 | {
28 | cout<>t;
41 | t=1;
42 | while(t--)
43 | solve();
44 | }
45 |
--------------------------------------------------------------------------------
/Codeforces Problems/116A.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | #define int long long
4 | #define endl "\n"
5 |
6 |
7 | int32_t main(){
8 | int t,mx=INT_MIN;
9 | cin>>t;
10 | int r = 0;
11 | while(t--){
12 | int a ,b;
13 | cin>>a>>b;
14 | r = r-a+b;
15 | mx = max(mx,r);
16 |
17 | }
18 | cout<
2 | using namespace std;
3 |
4 | int main(){
5 | string s;
6 | cin>>s;
7 |
8 | for(int i = 0 ; i = 'A' && s[i] <= 'Z'){
10 | s[i] += 32;
11 | }
12 | if(s[i] != 'a' &&s[i] != 'y' &&s[i] != 'e' &&s[i] != 'i' &&s[i] != 'o' &&s[i] != 'u'){
13 | cout<<'.'<
2 | using namespace std;
3 |
4 | int main(){
5 | int n;
6 | cin>>n;
7 |
8 | if(n%744 == 0 ||n%747==0 || n%47 == 0 ||n % 477 == 0 ||n%474==0 || n%4 ==0 || n%7 == 0){
9 | cout<<"YES"<
2 | using namespace std;
3 |
4 | int main() {
5 | int n, k;
6 | cin>>n>>k;
7 | int *arr = new int[n];
8 | for(int i=0; i>arr[i];
10 | int limit=arr[k-1], ans=0;
11 |
12 | for(int i=0; i=limit && arr[i]!=0)
14 | ans++;
15 | else
16 | break;
17 | }
18 |
19 | cout<
2 |
3 | using namespace std;
4 |
5 | int main(){
6 |
7 | int n,k;
8 | cin>>n>>k;
9 | int arr[n],count=0;
10 | for(int i=0;i>arr[i];}
11 | for(int i=0;i=arr[k-1]&&(arr[i]>0)) count++;
13 | else break;
14 | }
15 | cout<
2 | using namespace std;
3 | #define ll long long
4 | #define endl "\n"
5 |
6 | void solve()
7 | {
8 | ll n;
9 | cin >> n;
10 | cout << (long long)(-n + 1) << ' ' << (long long)(n) << '\n';
11 | }
12 |
13 | int main()
14 | {
15 |
16 | ios_base ::sync_with_stdio(false);
17 | cin.tie(NULL);
18 |
19 | int T;
20 | cin >> T;
21 | while (T--)
22 | solve();
23 | return 0;
24 | }
--------------------------------------------------------------------------------
/Codeforces Problems/1594B.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | #define ll long long
4 | #define endl "\n"
5 | const ll INF = 1e9 + 7;
6 |
7 | void solve()
8 | {
9 | ll n, k;
10 | cin >> n >> k;
11 | ll p = 1;
12 | ll ans = 0;
13 | for (int i = 0; i < 31; i++)
14 | {
15 | if (k & (1 << i))
16 | {
17 | ans = (ans + p) % INF;
18 | // cout << "ans-> " << ans << " " << (1 << i) << " ";
19 | // cout << "p-> " << p << " ";
20 | }
21 | p *= n;
22 | p %= INF;
23 | }
24 | cout << ans << '\n';
25 | }
26 |
27 | int main()
28 | {
29 |
30 | ios_base ::sync_with_stdio(false);
31 | cin.tie(NULL);
32 |
33 | int T;
34 | cin >> T;
35 | while (T--)
36 | solve();
37 | return 0;
38 | }
--------------------------------------------------------------------------------
/Codeforces Problems/1692A - Marathon.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int t;
7 | cin>>t;
8 |
9 | while(t--) {
10 | int a, b, c, d;
11 | cin>>a>>b>>c>>d;
12 | int count = 0;
13 |
14 | if(b>a)
15 | count++;
16 | if(c>a)
17 | count++;
18 | if(d>a)
19 | count++;
20 |
21 | cout<
2 | using namespace std;
3 |
4 | int main() {
5 | int n;
6 | cin>>n;
7 | int arr[1000][1000];
8 | int total = 0;
9 |
10 | for(int i=0; i>arr[i][j];
14 | if(arr[i][j]==1)
15 | c++;
16 | }
17 | if(c>1)
18 | total ++;
19 | }
20 |
21 | cout<
2 | #include
3 | #include
4 | using namespace std;
5 |
6 | int main(){
7 | string user_name;
8 | cin>>user_name;
9 | sort(user_name.begin(), user_name.end());
10 |
11 | for(int i=0; user_name[i]!='\0';) {
12 | if(user_name[i] == user_name[i+1])
13 | user_name.erase (user_name.begin() + i);
14 | else
15 | i++;
16 | }
17 |
18 | int size = user_name.size();
19 | if(size&1)
20 | cout<<"IGNORE HIM!";
21 | else
22 | cout<<"CHAT WITH HER!";
23 |
24 | return 0;
25 | }
--------------------------------------------------------------------------------
/Codeforces Problems/263A - Beautiful Matrix.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | int main() {
6 | int matrix[5][5];
7 | // Variables to store the location of '1'
8 | int one_i=0, one_j=0;
9 |
10 | // Inputting the matrix
11 | for(int i=0; i<5; i++) {
12 | for(int j=0; j<5; j++) {
13 | cin>>matrix[i][j];
14 | if(matrix[i][j]) {
15 | one_i = i+1;
16 | one_j = j+1;
17 | }
18 | }
19 | }
20 |
21 | int count = 0;
22 | count += abs(one_i-3);
23 | count += abs(one_j-3);
24 |
25 | cout<
2 | #include
3 |
4 | using namespace std;
5 |
6 | int main(){
7 |
8 | int T,x=0;cin>>T;
9 | string s;
10 | for(int i=0;i>s;
12 | if(s[1]=='-'){x--;}
13 | else x++;
14 | }
15 | cout<
2 | using namespace std;
3 |
4 | int main() {
5 | int w;
6 | cin>>w;
7 |
8 | if(w%2 || w==2)
9 | cout<<"NO";
10 | else
11 | cout<<"YES";
12 |
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/Codeforces Problems/50A - Domino piling.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | int m, n;
6 | cin>>m>>n;
7 | cout<<(m*n)/2;
8 | return 0;
9 | }
--------------------------------------------------------------------------------
/Codeforces Problems/50A.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(){
6 |
7 | int m,n;cin>>m>>n;
8 | cout<-1:
27 | ans=min(ans,left[i-1]+right[i])
28 | print(ans if ans!=float("inf") else 0)
--------------------------------------------------------------------------------
/Codeforces Problems/71A - Way Too Long Words.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | int main() {
6 | int n;
7 | cin>>n;
8 |
9 | while(n--) {
10 | string str;
11 | cin>>str;
12 | int size = str.length();
13 | if(size>10) {
14 | int i=1;
15 | while(str[i] != '\0')
16 | i++;
17 | cout<
2 | using namespace std;
3 | int main()
4 | {
5 | int t;
6 | float a,b,c,p,q,r;
7 | cin>>t;
8 | while(t--)
9 | {
10 | cin>>a>>b>>c>>p>>q>>r;
11 | double ans=(p+q+r)/2;
12 | if((a+b+c)>ans || (p+b+c)>ans || (a+q+c)>ans || (a+b+r)>ans)
13 | {
14 | cout<<"YES"<
10 | using namespace std;
11 |
12 | int main() {
13 | int tc,b;
14 | cin>>tc;
15 | while(tc!=0){
16 | int b;
17 | cin>>b;
18 | b=b-2;
19 | b=b/2;
20 | b=(b*(b+1))/2;
21 | cout<
2 | using namespace std;
3 | int facto(int p){
4 | int ans = 1;
5 | for(int i = p;p>=2;p--){
6 | ans *= p;
7 | }
8 | return ans;
9 | }
10 | int check(vectorv, int m){
11 | // mC2*4!/4 = m!/
12 | int ans,fans;
13 | ans = facto(m)/(facto(m-2)*2);
14 | fans = ans*6;
15 | return fans;
16 |
17 | }
18 | int main(){
19 | int t;
20 | cin>>t;
21 | while(t--){
22 | int n;
23 | cin>>n;
24 | vectorv(n);
25 | for(int i=0;i>v[i];
27 | }
28 | cout<
2 | using namespace std;
3 | int check(int arr[],int n){
4 | sort(arr, arr+n);
5 | for(int i=0;i>t;
15 | while(t--){
16 | int n;
17 | cin>>n;
18 | int arr[n];
19 | for(int i=0;i>arr[i];
21 | }
22 | if(check(arr,n))
23 | cout<<"yes"<
2 | using namespace std;
3 |
4 | int main(){
5 | int t;
6 | cin>>t;
7 | while(t--){
8 | int a,b,c;
9 | cin>>a>>b>>c;
10 |
11 | if( (a+b==c)|| (a+c==b)||(b+c==a))
12 | cout<<"yes"<
2 | using namespace std;
3 | int main()
4 | {
5 | int t;
6 | cin >> t;
7 | for(int i=0;i> n;
12 | if(n<=6)
13 | {
14 | time = 15;
15 | }
16 | else if(n%2==0)
17 | {
18 | time = (n*5)/2;
19 | }
20 | else
21 | {
22 | time = ((n+1)*5)/2;
23 | }
24 | cout << time << endl;
25 | }
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/Codeforces Problems/sort_zero.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main()
6 | {
7 | int t;cin>>t;
8 | while(t--)
9 | {
10 |
11 | int n;cin>>n;
12 | int a[n];
13 | for(int i=0;i>a[i];
15 | int pos=n-1;
16 | while(pos>0&&a[pos]>=a[pos-1]) pos--;
17 | map m;
18 | for(int i=0;i s;
26 | for(int i=0;i<=in;i++)
27 | s.insert(a[i]);
28 | cout<
2 | using namespace std;
3 |
4 |
5 | int helper(vector>& tri, int i, int j, vector>& dp){
6 | int n = tri.size() ;
7 |
8 | for(int j = 0; j < n; j++ ){
9 | dp[n-1][j] = tri[n-1][j] ;
10 | }
11 |
12 | for(int i = n-2; i >= 0; i--){
13 | for(int j = i; j >= 0; j-- ){
14 | dp[i][j] = tri[i][j] + max(dp[i+1][j] , dp[i+1][j+1]) ;
15 | }
16 | }
17 |
18 | return dp[0][0] ;
19 |
20 |
21 | }
22 |
23 |
24 | int maxSumPath(vector>& tri) {
25 | int n = tri.size() ;
26 |
27 | vector> dp(n, vector(n, -1) ) ;
28 |
29 | return helper(tri, 0, 0, dp) ;
30 | }
31 |
32 |
33 | int main()
34 | {
35 | vector > tri{ { 1 },
36 | { 2, 1 },
37 | { 3, 3, 2 } };
38 | cout << maxSumPath(tri);
39 | return 0;
40 | }
41 |
--------------------------------------------------------------------------------
/Floyd_Triangle.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | void printFloydTriangle(int n)
5 | {
6 | int i, j, val = 1;
7 | for (i = 1; i <= n; i++)
8 | {
9 | for (j = 1; j <= i; j++)
10 | cout << val++ << " ";
11 | cout << endl;
12 | }
13 | }
14 |
15 | int main()
16 | {
17 | printFloydTriangle(6);
18 | return 0;
19 | }
20 |
--------------------------------------------------------------------------------
/GFG/Kadanes_Algorithm.cpp:
--------------------------------------------------------------------------------
1 | public:
2 | // arr: input array
3 | // n: size of array
4 | //Function to find the sum of contiguous subarray with maximum sum.
5 | long long maxSubarraySum(int arr[], int n){
6 |
7 | // Your code here
8 | long long int max_sum=arr[0],res=arr[0];
9 | for(int i=1;i (arr[i]+max_sum)) ?arr[i]: (arr[i]+max_sum);
11 | res= (res> max_sum) ?res: max_sum;
12 | }
13 | return res;
14 |
15 | }
16 | };
17 |
18 |
19 | // Question - https://practice.geeksforgeeks.org/problems/kadanes-algorithm-1587115620/1
20 |
--------------------------------------------------------------------------------
/Google Kickstart 2022 Round G Walktober.py:
--------------------------------------------------------------------------------
1 | def solution(t):
2 | m, n, p = map(int, input().split())
3 | lst = []
4 | for i in range(m):
5 | lst.append(list(map(int, input().split())))
6 |
7 | steps = 0
8 | for i in range(n):
9 | max = lst[p-1][i]
10 | for j in range(m):
11 | if max < lst[j][i]:
12 | max = lst[j][i]
13 | steps = steps + max - lst[p-1][i]
14 |
15 | print("case #{0}: {1}".format(t+1, steps))
16 |
17 | test = int(input())
18 | for x in range(test):
19 | solution(x)
20 |
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/BFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/BFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Creating_And_displaying_a_graph.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Creating_And_displaying_a_graph.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_BFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_BFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_DFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_DFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_Directed_graph_DFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_Directed_graph_DFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_directed_graph_BFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_directed_graph_BFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/DFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/DFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Search_in_a_maze.cpp:
--------------------------------------------------------------------------------
1 | // Coded By Shreyash Shrivastava
2 |
3 | #include
4 | using namespace std;
5 |
6 | int main(){
7 | return 0;
8 | }
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Topological_Sort_DFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Topological_Sort_DFS.exe
--------------------------------------------------------------------------------
/Graphs questions from Love Babbar SDE sheet/Topological_sort_BFS.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Topological_sort_BFS.exe
--------------------------------------------------------------------------------
/Jump Game:
--------------------------------------------------------------------------------
1 | The problem can be think of as if you walk into i, how many available steps you have?
2 | if you have 0 steps left while the current value is 0, then you won't be able to go to the next step.
3 |
4 | The the question is how to calculate the current step, it is:
5 | max(--nlen,nums[i])
6 | since we reuse nlen, so I write it into two steps.
7 |
8 |
9 | class Solution {
10 | public:
11 | bool canJump(vector& nums) {
12 | int n = nums.size();
13 | if ( n == 1 ) return true;
14 |
15 | int nlen = nums[0];
16 |
17 | for ( int i = 1; i
2 | using namespace std;
3 |
4 | int max(int a, int b);
5 | int lcs( char *X, char *Y, int m, int n )
6 | {
7 | if (m == 0 || n == 0)
8 | return 0;
9 | if (X[m-1] == Y[n-1])
10 | return 1 + lcs(X, Y, m-1, n-1);
11 | else
12 | return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
13 | }
14 |
15 | int max(int a, int b)
16 | {
17 | return (a > b)? a : b;
18 | }
19 |
20 | int main()
21 | {
22 | char X[] = "AGGTAB";
23 | char Y[] = "GXTXAYB";
24 |
25 | int m = strlen(X);
26 | int n = strlen(Y);
27 |
28 | cout<<"Length of Longest Common Subsequence is "<< lcs( X, Y, m, n ) ;
29 |
30 | return 0;
31 | }
32 |
--------------------------------------------------------------------------------
/Leetcode Easy/ContainsDuplicate.java:
--------------------------------------------------------------------------------
1 | import java.util.HashSet;
2 | import java.util.Set;
3 |
4 | public class ContainsDuplicate {
5 |
6 | public static boolean containsDuplicate(int[] nums) {
7 |
8 | Set unique = new HashSet();
9 |
10 | for (int i = 0; i < nums.length; i++) {
11 | unique.add(nums[i]);
12 | }
13 |
14 | if (unique.size() == nums.length)
15 | return false;
16 | return true;
17 |
18 | }
19 |
20 | public static void main(String args[]) {
21 | int numbers[] = { 1, 2, 2, 3 };
22 |
23 | if (containsDuplicate(numbers)) {
24 | System.out.println("Duplicates present");
25 | } else
26 | System.out.println("Duplicates not present");
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/Leetcode Easy/Divide_Array_Into_Equal_Pairs.java:
--------------------------------------------------------------------------------
1 | // Link to the problem:https://leetcode.com/problems/divide-array-into-equal-pairs/
2 |
3 | class Solution {
4 | public boolean divideArray(int[] nums) {
5 | int[] count=new int[501];
6 | for(int i:nums){
7 | count[i]++;
8 | }
9 | for(int i:count){
10 | if((i&1)==1){
11 | return false;
12 | }
13 | }
14 | return true;
15 | }
16 | }
--------------------------------------------------------------------------------
/Leetcode Easy/InvertedBinaryTree.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * Definition for a binary tree node.
3 | * struct TreeNode {
4 | * int val;
5 | * TreeNode *left;
6 | * TreeNode *right;
7 | * TreeNode() : val(0), left(nullptr), right(nullptr) {}
8 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10 | * };
11 | */
12 | class Solution {
13 | public:
14 | TreeNode* invertTree(TreeNode* root) {
15 | if(root==NULL){
16 | return NULL;
17 | }
18 | else{
19 | TreeNode* l=invertTree(root->left);
20 | TreeNode* r=invertTree(root->right);
21 |
22 | root->left=r;
23 | root->right=l;
24 | }
25 | return root;
26 |
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/Leetcode Easy/Leetcode.java:
--------------------------------------------------------------------------------
1 | \// java function to return true if contain duplicate
2 | public boolean containsDuplicate(int[] nums) {
3 | Arrays.sort(nums);
4 | for(int i=0;i<=nums.length-2;i++)
5 | {
6 | if(nums[i]==nums[i+1])
7 | return true;
8 | }
9 | return false;
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/Leetcode Easy/LongestCommonPrefix.java:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 |
3 | public class LongestCommonPrefix {
4 |
5 | public static String longestCommonPrefix(String[] strs) {
6 |
7 | Arrays.sort(strs);
8 |
9 | int count = 0;
10 |
11 | String first = strs[0];
12 | String last = strs[strs.length - 1];
13 |
14 | while (count < first.length()) {
15 | if (first.charAt(count) == last.charAt(count))
16 | count++;
17 | else
18 | break;
19 | }
20 |
21 | return count == 0 ? "" : first.substring(0, count);
22 |
23 | }
24 |
25 | public static void main(String args[]) {
26 | String strs[] = { "flower", "flow", "flight" };
27 | System.out.println(longestCommonPrefix(strs));
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/Leetcode Easy/Powe Of Three.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | bool isPowerOfThree(int n) {
4 | long long temp= 1;
5 | while(temp<= n){
6 | if(n== temp){
7 | return true;
8 | }
9 | temp*= 3;
10 | }
11 | return false;
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/Leetcode Easy/RemoveElement.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int removeElement(vector& nums, int val) {
4 | int n = nums.size();
5 | int j = 0;
6 | for(int i = 0; i List[int]:
3 | freq = Counter(nums)
4 | ans = [-1, -1]
5 | for x in range(1, len(nums) + 1):
6 | if x not in freq:
7 | ans[1] = x
8 | if freq[x] > 1:
9 | ans[0] = x
10 | return ans
--------------------------------------------------------------------------------
/Leetcode Easy/SingleNumber.java:
--------------------------------------------------------------------------------
1 | //problem link: https://leetcode.com/problems/single-number/
2 |
3 | class Solution {
4 | public int singleNumber(int[] nums) {
5 | int sum = 0;
6 | for (int i = 0; i val!=ptr2->val)
25 | return false;
26 | return isMirror(ptr1->left,ptr2->right)&&isMirror(ptr1->right,ptr2->left);
27 | }
28 | bool isSymmetric(struct TreeNode* root){
29 | if(!root)
30 | return true;
31 | return isMirror(root->left,root->right);
32 | }
33 |
--------------------------------------------------------------------------------
/Leetcode Easy/reverse_linked_list.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | ListNode* reverseList(ListNode* head) {
4 | ListNode *nextNode, *prevNode = NULL;
5 | while (head) {
6 | nextNode = head->next;
7 | head->next = prevNode;
8 | prevNode = head;
9 | head = nextNode;
10 | }
11 | return prevNode;
12 | }
13 | };
--------------------------------------------------------------------------------
/Leetcode Easy/twosum.java:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int[] twoSum(int[] nums, int target) {
3 | int[] answer = new int[2];
4 | for (int i = 0 ; i < nums.length - 1 ; i ++) {
5 | for (int j = i + 1; j < nums.length; j++) {
6 | if(nums[i] + nums[j] == target) {
7 | answer[0] = i;
8 | answer[1] = j;
9 | return answer;
10 | }
11 | }
12 | }
13 | return answer;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Leetcode Problems/136. Single Number.java:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public int singleNumber(int[] nums) {
3 | Map lol = new TreeMap