Thank you for your general way of writing a comparer! Very helpful.
Junzhi
@new2500
Posts made by new2500

RE: C# version by SortedList

RE: Simple Java solution using one array and two pointers
Thanks for your clarification butI still don't get why string S is determined by the first char S[0].....And how it will be a "logically" duplicated.... Sorry about my bad math...

RE: Simple Java solution using one array and two pointers
@shawngao said in Simple Java solution using one array and two pointers:
Create two pointers head and tail. head points to the number which will be used to generate new numbers. tail points to the next empty position to put the new number. Then keep generating new numbers until tail >= n.
I hate Advanced Math.... I know it's Kolakoski sequence but I still don't know what's the trick to generating the next number.
I draw a graph:
1 2 2 X M head: ^ tail: ^
Why will the X be 1 if we don't know what the M is?

RE: A general approach to backtracking questions in Java (Subsets, Permutations, Combination Sum, Palindrome Partitioning)
They keys are
backtrack(list, tempList, nums, i + 1); tempList.remove(tempList.size()  1);
Execute next statement the "Remove last element". Then this level is completed, return back to the previous backtracking level.
I attach the a simple graph of history of "list" in the whole call for input array "1,2,3", also some pointers for understanding. You might get a clue:
empty > 1 > 1,2 > 1,2,3 > 1,2 > 1 > 1,3 > 2,3 > 1,2,3 ^ ^ 1st level loop:i=0 ^ ^ 1st level: i = 1 2nd level loop: i = 1 2nd level loop: i = 2, 2nd ends ......

RE: C#  solutions to Spiral Matrix 1 and 2  nearly the same
I like your code style. Intuitive and easy to understand. Writing comments is a very good habit. Thank you.

RE: Backtracking solution
@xiangxy
In my opinion:
the first for loop within the countNumbersWithUniqueDigits, starting from 1, end at 9. Without considering the leading 0 case. That's why we need a max value in the search method to act as "loop stopper" in the search method.if (prev < max) count++; else return count; //reach max, return
Jump to search method, The first "prev" only consider 19, and the first i in the search method is 0, then we call the search again, the current value become 10*prev(10,20,30....90) + i(Now the i could be 0~9) .
Hope it helps.

RE: Why "++++++++++" is a TRUE?
Obviously, 1P can win.
flip two consecutive "++" into ""++++++++++ input ++++++++ 1P moved ++++++ 2P moved ++++ 1P moved ++ 2P moved  1P moved No room for 2P, 1P win

RE: Anybody know the Time Complexity of the Recur Solution?
I quote @jeantimex 's time complexity analysis.
For the time complexity, here is what I thought, let's say the length of the input string s is n, there are at most n  1 ways to replace "++" to "" (imagine s is all "+++..."), once we replace one "++", there are at most (n  2)  1 ways to do the replacement, it's a little bit like solving the NQueens problem, the time complexity is (n  1) x (n  3) x (n  5) x ..., so it's O(n!!), double factorial.
see https://discuss.leetcode.com/topic/27250/sharemyjavabacktrackingsolution

RE: Share my Java backtracking solution
@jeantimex said in Share my Java backtracking solution:
s.charAt(i) == '+' && s.charAt(i + 1) == '+' can be shorten as s.startsWith("++", i)
Not Sure about StartWith method in Java, but if using StartWith method in C#. (StartWith method in C# doesn't have (string value, int offset), have to Substring first then use StartWith), Runtime if double slower than directly use (s[i] == '+' && s[i+1]=='+')