Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
Binary file added algorithms/cpp/3Sum/3Sum.exe
Binary file not shown.
Binary file added algorithms/cpp/3Sum/3Sum.o
Binary file not shown.
Binary file added algorithms/cpp/3Sum/build/Debug/3Sum.o
Binary file not shown.
Binary file added algorithms/cpp/3Sum/build/Debug/outDebug.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*
*
***************************************************************************************/


Expand All @@ -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<bits/stdc++.h>
#define zeros(i) (i ^ (i - 1)) & i
class Solution {
public:
vector <int> sorted, sol, fenwick;
vector <int> sorted;

int n;
int search(int t)
{
Expand Down Expand Up @@ -60,7 +62,7 @@ class Solution {
sorted = nums;
n = nums.size();
sort(sorted.begin(), sorted.end());
vector <int> f(sorted.size());
vector <int> f(sorted.size()+1);
fenwick = f;
for(int i = nums.size() - 1; i >= 0; i--)
{
Expand All @@ -75,15 +77,15 @@ class Solution {
};


/***************************************************************************************
/***************************************************************************************
* Another solution - Binary Search Tree
***************************************************************************************/


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;
Expand Down Expand Up @@ -147,6 +149,6 @@ class Solution {
tree.insert( nums[i], numLessThan);
counts[i] = numLessThan;
}
return counts;
return counts;
}
};