diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 000000000..f91284705 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x86", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/MinGW/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x86", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..66d6e2c5a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/HP/OneDrive - Charutar Vidya Mandal Educational trust/Desktop/git demo/leetcodee/algorithms/cpp/3Sum", + "program": "c:/Users/HP/OneDrive - Charutar Vidya Mandal Educational trust/Desktop/git demo/leetcodee/algorithms/cpp/3Sum/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..c9e66f12e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..4632a0eb3 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:/MinGW/bin/gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe", + "" + ], + "options": { + "cwd": "C:/MinGW/bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/algorithms/cpp/3Sum/3Sum.exe b/algorithms/cpp/3Sum/3Sum.exe new file mode 100644 index 000000000..1b8e0dce6 Binary files /dev/null and b/algorithms/cpp/3Sum/3Sum.exe differ diff --git a/algorithms/cpp/3Sum/3Sum.o b/algorithms/cpp/3Sum/3Sum.o new file mode 100644 index 000000000..a754b6608 Binary files /dev/null and b/algorithms/cpp/3Sum/3Sum.o differ diff --git a/algorithms/cpp/3Sum/build/Debug/3Sum.o b/algorithms/cpp/3Sum/build/Debug/3Sum.o new file mode 100644 index 000000000..cd22c6fed Binary files /dev/null and b/algorithms/cpp/3Sum/build/Debug/3Sum.o differ diff --git a/algorithms/cpp/3Sum/build/Debug/outDebug.exe b/algorithms/cpp/3Sum/build/Debug/outDebug.exe new file mode 100644 index 000000000..ef0def229 Binary files /dev/null and b/algorithms/cpp/3Sum/build/Debug/outDebug.exe differ diff --git a/algorithms/cpp/countOfSmallerNumbersAfterSelf/countOfSmallerNumbersAfterSelf.cpp b/algorithms/cpp/countOfSmallerNumbersAfterSelf/countOfSmallerNumbersAfterSelf.cpp index badec47d2..63fe0dbbf 100644 --- a/algorithms/cpp/countOfSmallerNumbersAfterSelf/countOfSmallerNumbersAfterSelf.cpp +++ b/algorithms/cpp/countOfSmallerNumbersAfterSelf/countOfSmallerNumbersAfterSelf.cpp @@ -2,23 +2,23 @@ // Author : Calinescu Valentin, Hao Chen // Date : 2015-12-08 -/*************************************************************************************** +/*************************************************************************************** * - * You are given an integer array nums and you have to return a new counts array. The - * counts array has the property where counts[i] is the number of smaller elements to + * You are given an integer array nums and you have to return a new counts array. The + * counts array has the property where counts[i] is the number of smaller elements to * the right of nums[i]. - * + * * Example: - * + * * Given nums = [5, 2, 6, 1] - * + * * To the right of 5 there are 2 smaller elements (2 and 1). * To the right of 2 there is only 1 smaller element (1). * To the right of 6 there is 1 smaller element (1). * To the right of 1 there is 0 smaller element. - * + * * Return the array [2, 1, 1, 0]. - * + * ***************************************************************************************/ @@ -27,10 +27,12 @@ // 1) http://www.geeksforgeeks.org/binary-indexed-tree-or-fenwick-tree-2/ // 2) http://cs.stackexchange.com/questions/10538/bit-what-is-the-intuition-behind-a-binary-indexed-tree-and-how-was-it-thought-a +#include #define zeros(i) (i ^ (i - 1)) & i class Solution { public: - vector sorted, sol, fenwick; + vector sorted; + int n; int search(int t) { @@ -60,7 +62,7 @@ class Solution { sorted = nums; n = nums.size(); sort(sorted.begin(), sorted.end()); - vector f(sorted.size()); + vector f(sorted.size()+1); fenwick = f; for(int i = nums.size() - 1; i >= 0; i--) { @@ -75,7 +77,7 @@ class Solution { }; -/*************************************************************************************** +/*************************************************************************************** * Another solution - Binary Search Tree ***************************************************************************************/ @@ -83,7 +85,7 @@ class Solution { class BinarySearchTreeNode { public: - int val; + int val; int less; // count of members less than val int count; // count of members equal val BinarySearchTreeNode *left, *right; @@ -147,6 +149,6 @@ class Solution { tree.insert( nums[i], numLessThan); counts[i] = numLessThan; } - return counts; + return counts; } };