Skip to content

Commit bb0d36e

Browse files
author
junl
committed
update some
1 parent 8ef30c7 commit bb0d36e

File tree

25 files changed

+767
-28
lines changed

25 files changed

+767
-28
lines changed

alg-cpp.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@
181181
0922310922FA497500F0F5AF /* searchInsert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = searchInsert.h; sourceTree = "<group>"; };
182182
0922310C22FA50DD00F0F5AF /* maxSubArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = maxSubArray.h; sourceTree = "<group>"; };
183183
0922310F22FAFEEE00F0F5AF /* merge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = merge.h; sourceTree = "<group>"; };
184+
0922D94323CCBC7F00E7EF1E /* IsContinuous2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IsContinuous2.h; sourceTree = "<group>"; };
185+
0922D94623CCC58B00E7EF1E /* LastRemaining_Solution.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LastRemaining_Solution.h; sourceTree = "<group>"; };
184186
0924B8E622F9D8A400435980 /* twoSum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = twoSum.h; sourceTree = "<group>"; };
185187
0924B8E922F9E06000435980 /* removeDuplicates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removeDuplicates.h; sourceTree = "<group>"; };
186188
09255F962360A57300B38E3D /* getMaxRectSize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = getMaxRectSize.h; sourceTree = "<group>"; };
@@ -204,6 +206,7 @@
204206
0943DB3D2382EDEE00E995BB /* getIntersectNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = getIntersectNode.h; sourceTree = "<group>"; };
205207
094524B7234790CD00CCBFB9 /* coinChange.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = coinChange.h; sourceTree = "<group>"; };
206208
094524BA234A32D000CCBFB9 /* levenshtein_distance.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = levenshtein_distance.h; sourceTree = "<group>"; };
209+
09452DC323A7D56700737465 /* removeRepeatNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = removeRepeatNode.h; sourceTree = "<group>"; };
207210
0946B01522F68BA50043469D /* FirstNotRepeatingChar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstNotRepeatingChar.h; sourceTree = "<group>"; };
208211
0946B01822F695CE0043469D /* ReverseSentence.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReverseSentence.h; sourceTree = "<group>"; };
209212
0946B01B22F6A5BF0043469D /* StrToInt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StrToInt.h; sourceTree = "<group>"; };
@@ -232,6 +235,7 @@
232235
095A524923364FC800D29259 /* permutation_sequence.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = permutation_sequence.h; sourceTree = "<group>"; };
233236
095A524C23371ADA00D29259 /* combinations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = combinations.h; sourceTree = "<group>"; };
234237
095A524F2339193400D29259 /* subsets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = subsets.h; sourceTree = "<group>"; };
238+
095D844523C0476800102FB0 /* ReOrder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReOrder.h; sourceTree = "<group>"; };
235239
095E32C223706CCA00331B4A /* josephusKill.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = josephusKill.h; sourceTree = "<group>"; };
236240
095F60122322B3390072CF0C /* searchInRotatedSortedArrayII.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = searchInRotatedSortedArrayII.h; sourceTree = "<group>"; };
237241
0965B3CB23045219009A153E /* lengthOfLastWord.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lengthOfLastWord.h; sourceTree = "<group>"; };
@@ -280,6 +284,8 @@
280284
09BEFF3622E141D300FF7CD3 /* kthSmallest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = kthSmallest.h; sourceTree = "<group>"; };
281285
09C5E0D82301C30300EDD63B /* strStr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = strStr.h; sourceTree = "<group>"; };
282286
09C8705F231D5EBE00ABE173 /* bucketSort.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = bucketSort.h; sourceTree = "<group>"; };
287+
09C9413823BF8AB00086EDAE /* Print1ToMaxOfNDigits.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Print1ToMaxOfNDigits.h; sourceTree = "<group>"; };
288+
09C9413B23BF983C0086EDAE /* DeleteNodeO1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeleteNodeO1.h; sourceTree = "<group>"; };
283289
09CA9FAD2318A7A500BE2B39 /* combinationSum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = combinationSum.h; sourceTree = "<group>"; };
284290
09CA9FAE2318A7A500BE2B39 /* permutations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = permutations.h; sourceTree = "<group>"; };
285291
09CA9FAF2319744400BE2B39 /* longestUnivaluePath.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = longestUnivaluePath.h; sourceTree = "<group>"; };
@@ -675,6 +681,8 @@
675681
3A65DBC822F813F10026166D /* FindNumbersWithSum.h */,
676682
3A65DBCB22F819060026166D /* FindContinuousSequence.h */,
677683
3A65DBCE22F823AD0026166D /* GetUglyNumber_Solution.h */,
684+
09C9413823BF8AB00086EDAE /* Print1ToMaxOfNDigits.h */,
685+
0922D94323CCBC7F00E7EF1E /* IsContinuous2.h */,
678686
);
679687
path = "coding-interviews";
680688
sourceTree = "<group>";
@@ -694,6 +702,7 @@
694702
0943DB3A2382E20100E995BB /* addList.h */,
695703
0943DB3D2382EDEE00E995BB /* getIntersectNode.h */,
696704
091E1CED238EBFB100680649 /* reverseKNodes.h */,
705+
09452DC323A7D56700737465 /* removeRepeatNode.h */,
697706
);
698707
path = itinterviews;
699708
sourceTree = "<group>";
@@ -848,6 +857,7 @@
848857
09E18E5A22F56EDB002D0227 /* PrintMinNumber.h */,
849858
09E18E5D22F58301002D0227 /* GetNumberOfK.h */,
850859
09E18E6022F588E8002D0227 /* FindNumsAppearOnce.h */,
860+
095D844523C0476800102FB0 /* ReOrder.h */,
851861
);
852862
path = "coding-interviews";
853863
sourceTree = "<group>";
@@ -934,6 +944,8 @@
934944
3A091A7422F41C4200EFA79C /* FindFirstCommonNode.h */,
935945
3A091A7722F4201800EFA79C /* deleteDuplication.h */,
936946
3A091A6B22F3E3F600EFA79C /* creatlist.h */,
947+
09C9413B23BF983C0086EDAE /* DeleteNodeO1.h */,
948+
0922D94623CCC58B00E7EF1E /* LastRemaining_Solution.h */,
937949
);
938950
path = "coding-interviews";
939951
sourceTree = "<group>";
17.5 KB
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
uuid = "6057182A-5432-40CB-A6E9-927652D280FB"
4+
type = "0"
5+
version = "2.0">
6+
<Breakpoints>
7+
<BreakpointProxy
8+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
9+
<BreakpointContent
10+
uuid = "913CEDB4-C9B6-42F9-95F7-02DCA02D2CBF"
11+
shouldBeEnabled = "Yes"
12+
ignoreCount = "0"
13+
continueAfterRunningActions = "No"
14+
filePath = "../alg-cpp/main.cpp"
15+
startingColumnNumber = "9223372036854775807"
16+
endingColumnNumber = "9223372036854775807"
17+
startingLineNumber = "69"
18+
endingLineNumber = "69"
19+
landmarkName = "reconstructQueue(people)"
20+
landmarkType = "7">
21+
</BreakpointContent>
22+
</BreakpointProxy>
23+
</Breakpoints>
24+
</Bucket>
40.2 KB
Binary file not shown.

alg-cpp.xcodeproj/xcuserdata/junlongj.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,86 @@
22
<Bucket
33
type = "1"
44
version = "2.0">
5+
<Breakpoints>
6+
<BreakpointProxy
7+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+
<BreakpointContent
9+
shouldBeEnabled = "Yes"
10+
ignoreCount = "0"
11+
continueAfterRunningActions = "No"
12+
filePath = "tree/leetcode/buildTree.h"
13+
timestampString = "599563890.931828"
14+
startingColumnNumber = "9223372036854775807"
15+
endingColumnNumber = "9223372036854775807"
16+
startingLineNumber = "83"
17+
endingLineNumber = "83"
18+
landmarkName = "reConstructBinaryTree(vector&lt;int&gt; &amp;pre,vector&lt;int&gt; &amp;vin, int pstart,int pend,int vstart, int vend)"
19+
landmarkType = "9">
20+
</BreakpointContent>
21+
</BreakpointProxy>
22+
<BreakpointProxy
23+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
24+
<BreakpointContent
25+
shouldBeEnabled = "Yes"
26+
ignoreCount = "0"
27+
continueAfterRunningActions = "No"
28+
filePath = "tree/leetcode/buildTree.h"
29+
timestampString = "599563890.932268"
30+
startingColumnNumber = "9223372036854775807"
31+
endingColumnNumber = "9223372036854775807"
32+
startingLineNumber = "77"
33+
endingLineNumber = "77"
34+
landmarkName = "reConstructBinaryTree(vector&lt;int&gt; &amp;pre,vector&lt;int&gt; &amp;vin, int pstart,int pend,int vstart, int vend)"
35+
landmarkType = "9">
36+
</BreakpointContent>
37+
</BreakpointProxy>
38+
<BreakpointProxy
39+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
40+
<BreakpointContent
41+
shouldBeEnabled = "Yes"
42+
ignoreCount = "0"
43+
continueAfterRunningActions = "No"
44+
filePath = "tree/main.cpp"
45+
timestampString = "599828687.318513"
46+
startingColumnNumber = "9223372036854775807"
47+
endingColumnNumber = "9223372036854775807"
48+
startingLineNumber = "118"
49+
endingLineNumber = "118"
50+
landmarkName = "main(int argc, const char * argv[])"
51+
landmarkType = "9">
52+
</BreakpointContent>
53+
</BreakpointProxy>
54+
<BreakpointProxy
55+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
56+
<BreakpointContent
57+
shouldBeEnabled = "Yes"
58+
ignoreCount = "0"
59+
continueAfterRunningActions = "No"
60+
filePath = "array/coding-interviews/PrintMinNumber.h"
61+
timestampString = "599927151.914993"
62+
startingColumnNumber = "9223372036854775807"
63+
endingColumnNumber = "9223372036854775807"
64+
startingLineNumber = "78"
65+
endingLineNumber = "78"
66+
landmarkName = "test_PrintMinNumber()"
67+
landmarkType = "9">
68+
</BreakpointContent>
69+
</BreakpointProxy>
70+
<BreakpointProxy
71+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
72+
<BreakpointContent
73+
shouldBeEnabled = "Yes"
74+
ignoreCount = "0"
75+
continueAfterRunningActions = "No"
76+
filePath = "array/coding-interviews/PrintMinNumber.h"
77+
timestampString = "599927157.866888"
78+
startingColumnNumber = "9223372036854775807"
79+
endingColumnNumber = "9223372036854775807"
80+
startingLineNumber = "71"
81+
endingLineNumber = "71"
82+
landmarkName = "PrintMinNumber2(vector&lt;int&gt; numbers)"
83+
landmarkType = "9">
84+
</BreakpointContent>
85+
</BreakpointProxy>
86+
</Breakpoints>
587
</Bucket>

alg-cpp.xcodeproj/xcuserdata/junlongj.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
<key>base.xcscheme_^#shared#^_</key>
2525
<dict>
2626
<key>orderHint</key>
27-
<integer>7</integer>
27+
<integer>5</integer>
2828
</dict>
2929
<key>bsearch.xcscheme_^#shared#^_</key>
3030
<dict>
3131
<key>orderHint</key>
32-
<integer>8</integer>
32+
<integer>9</integer>
3333
</dict>
3434
<key>divideandconquer.xcscheme_^#shared#^_</key>
3535
<dict>
3636
<key>orderHint</key>
37-
<integer>13</integer>
37+
<integer>14</integer>
3838
</dict>
3939
<key>dp.xcscheme_^#shared#^_</key>
4040
<dict>
4141
<key>orderHint</key>
42-
<integer>12</integer>
42+
<integer>10</integer>
4343
</dict>
4444
<key>greed.xcscheme_^#shared#^_</key>
4545
<dict>
@@ -49,12 +49,12 @@
4949
<key>hasTable.xcscheme_^#shared#^_</key>
5050
<dict>
5151
<key>orderHint</key>
52-
<integer>10</integer>
52+
<integer>11</integer>
5353
</dict>
5454
<key>linkedList.xcscheme_^#shared#^_</key>
5555
<dict>
5656
<key>orderHint</key>
57-
<integer>9</integer>
57+
<integer>6</integer>
5858
</dict>
5959
<key>other.xcscheme_^#shared#^_</key>
6060
<dict>
@@ -64,17 +64,17 @@
6464
<key>recursion.xcscheme_^#shared#^_</key>
6565
<dict>
6666
<key>orderHint</key>
67-
<integer>14</integer>
67+
<integer>13</integer>
6868
</dict>
6969
<key>sort.xcscheme_^#shared#^_</key>
7070
<dict>
7171
<key>orderHint</key>
72-
<integer>5</integer>
72+
<integer>8</integer>
7373
</dict>
7474
<key>stack+queue.xcscheme_^#shared#^_</key>
7575
<dict>
7676
<key>orderHint</key>
77-
<integer>6</integer>
77+
<integer>7</integer>
7878
</dict>
7979
<key>string.xcscheme_^#shared#^_</key>
8080
<dict>
@@ -84,7 +84,7 @@
8484
<key>tree.xcscheme_^#shared#^_</key>
8585
<dict>
8686
<key>orderHint</key>
87-
<integer>11</integer>
87+
<integer>12</integer>
8888
</dict>
8989
</dict>
9090
<key>SuppressBuildableAutocreation</key>

alg-cpp/main.cpp

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <iostream>
1010
#include <vector>
1111
#include <string>
12-
12+
#include <string>
13+
#include <stack>
14+
using namespace std;
1315
std::string FilterRepeatString(std::string &s){
1416
if (s.empty()) return s;
1517
s+='%';
@@ -33,10 +35,85 @@ std::string FilterRepeatString(std::string &s){
3335
}
3436
return result;
3537
}
38+
class Solution {
39+
public:
40+
static bool Compare(const vector<int> &l, const vector<int> &r){
41+
return l[0] > r[0];
42+
}
43+
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
44+
vector<vector<int>> res;
45+
if (people.empty() || people[0].size() != 2){
46+
return res;
47+
}
48+
sort(people.begin(), people.end(), Compare);
3649

50+
for (int i = 1; i < people.size(); i++){
51+
for(int j=0;j<i;j++){
52+
if (people[i][0] == people[j][0]){
53+
if (people[i][1] < people[j][1]){
54+
int cnt = people[i][1];
55+
vector<int> r = people[i];
56+
people.erase(people.begin() + i);
57+
people.insert(people.begin() + cnt, r);
58+
break;
59+
}
60+
}else{
61+
int cnt = people[i][1];
62+
vector<int> r = people[i];
63+
people.erase(people.begin() + i);
64+
people.insert(people.begin() + cnt, r);
65+
break;
66+
}
67+
}
68+
}
69+
return people;
70+
}
71+
};
72+
class Solution2 {
73+
public:
74+
bool canPartition(vector<int>& nums) {
75+
int sum = 0;
76+
for (auto &i : nums){
77+
sum+=i;
78+
}
79+
if (sum & 0x1){
80+
return false;
81+
}
82+
int v = sum / 2;
83+
int idx = -1;
84+
helper2(nums, idx, v);
85+
return st;
86+
}
87+
void helper2(vector<int &> &nums,int idx, int sum){
88+
if (sum == 0){
89+
st = true;
90+
return;
91+
}
92+
93+
for(int i=idx+1; i < nums.size();i++){
94+
if(sum > nums[i]){
95+
helper2(nums, i, sum - nums[i]);
96+
helper2(nums, i, sum);
97+
}
98+
}
99+
}
100+
bool st;
101+
};
37102
int main(int argc, const char * argv[]) {
38103
// insert code here...
39104
std::string s{"aabccccaab"};
40105
std::cout << FilterRepeatString(s) << std::endl;
106+
Solution so;
107+
// string s2 = "3[a2[c]]";//"3[a2[c]]"
108+
// s2 = so.decodeString(s2);
109+
vector<vector<int>> r;
110+
r.insert(r.begin()+2, {1});
111+
// r.push_back({7,0});
112+
// r.push_back({4,4});
113+
// r.push_back({7,1});
114+
// r.push_back({5,0});
115+
// r.push_back({6,1});
116+
// r.push_back({5,2});
117+
// so.reconstructQueue(r);
41118
return 0;
42119
}

array/coding-interviews/PrintMinNumber.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,37 @@ namespace codinginterviews {
4545
}
4646
return s;
4747
}
48+
#pragma mark - v2
49+
using namespace std;
50+
vector<string> results;
51+
void permutation(vector<int> &numbers, string str, vector<bool> st, int level){
52+
if (level == numbers.size()){
53+
results.push_back(str);
54+
return;
55+
}
56+
57+
for (int i=0;i<numbers.size();i++){
58+
if (st[i]) continue;
59+
st[i] = true;
60+
permutation(numbers, str+to_string(numbers[i]), st, level + 1);
61+
st[i] = false;
62+
}
63+
}
64+
string PrintMinNumber2(vector<int> numbers) {
65+
if (numbers.empty()) return "";
66+
vector<bool> st;
67+
st.resize(numbers.size());
68+
fill(st.begin(), st.end(), false);
69+
string str;
70+
permutation(numbers, str, st, 0);
71+
sort(results.begin(), results.end());
72+
return results[0];
73+
}
4874

4975
void test_PrintMinNumber(){
5076
std::vector<int> a{3,32,321};
5177
std::cout << "test_PrintMinNumber starting........" << std::endl;
52-
std::cout << PrintMinNumber(a) << std::endl;
78+
std::cout << PrintMinNumber2(a) << std::endl;
5379
}
5480
}
5581
#endif /* PrintMinNumber_hpp */

0 commit comments

Comments
 (0)