Showing posts with label parentheses. Show all posts
Showing posts with label parentheses. Show all posts

Wednesday, January 20, 2016

Leetcode questions 20: Valid Parentheses

January 20, 2016 

Leetcode 20: Valid parentheses


Julia’s C# code:

January 20, 2016

favorite blogs to read: January 20, 2016

Great time to go over different ideas to implement the algorithm, using Map in C++, Hashmap, and see so many talents through those code - 






http://www.jiuzhang.com/solutions/valid-parentheses/

So, ready to review more about parentheses:

Leetcode 32: longest valid parentheses -

Julia’s blog on this question:
Leetcode question 22: Generate Parentheses
https://github.com/jianminchen/Leetcode_C-/blob/master/GenerateParentheses_No22.cs


Wednesday, October 28, 2015

Leetcode question 241: Different ways to add parentheses

10/28/2015  

  Read the blog,

  http://fisherlei.blogspot.ca/2015/10/leetcode-different-ways-to-add.html

  http://blog.csdn.net/guanzhongshan/article/details/48086695

  and write C# code, compile it, build it, pass online judge, check in Github, and then, write a new code using memorization.

1. First step, write down C# code, compile ok.

https://github.com/jianminchen/Leetcode_C-/blob/master/241DifferentWaysToAddParentheses.cs

2. Read the most popular blog about this leetcode question through Google,
http://blog.csdn.net/sbitswc/article/details/48546421

and then, take Java code as a sample, write C# version of implementation.

https://github.com/jianminchen/Leetcode_C-/blob/master/241DifferentWaysToAddParentheses_B.cs

read the leetcode string algorithms blog (A plus):
http://blog.csdn.net/sbitswc/article/details/20429853

The leetcode question 241 is just a medium  question in difficulties.

Dec. 17, 2015
Review the solution, and then, need to write down the solution - a script to help solve the problem:
1. 1+2*3
-> read a substring from leftmost to convert it to number, for the example, read '1', integer 1, and then, visit '+' stop,
-> now, let us use recursive function call to get the first part of substring before '+', and get second part of substring after '+', and then, two lists, each one of list1 will operate '+' with each one of list2, add into return list.

Not convincing, try again:
use binary tree to model this problem:
http://juliachencoding.blogspot.ca/2015/12/oo-principle-solid-open-close-principle.html

So, get the root node - operator, and then, deal with left child, right child, and root node does the evaluate function.







Saturday, August 22, 2015

Leetcode questions 11 - 20

August 22, 2015


11 Container with Most water
blog:
http://www.cnblogs.com/TenosDoIt/p/3812880.html

C#:
https://github.com/jianminchen/Leetcode_C-/blob/master/11ContainerWithMostWater.cs

12. Integer to Roman


13 Roman to Integer

https://github.com/jianminchen/Leetcode_C-/blob/master/13RomanToInteger.cs

14. LOngest Common Prefix

https://github.com/jianminchen/Leetcode_C-/blob/master/LongestCommonPrefix_No14.cs

15. 3Sum

16 3 Sum Closest

https://github.com/jianminchen/Leetcode_C-/blob/master/3sumCloset.cs

17 Letter Combinations of a phone number (DFS)

http://www.cnblogs.com/grandyang/p/4452220.html
Analysis from the above blog:
这道题让我们求电话号码的字母组合,即数字2到9中每个数字可以代表若干个字母,然后给一串数字,求出所有可能的组合,相类似的题目有 Path Sum II 二叉树路径之和之二Subsets II 子集合之二Permutations 全排列Permutations II 全排列之二Combinations 组合项 Combination Sum 组合之和 Combination Sum II 组合之和之二等等。我们用递归Recursion来解,我们需要建立一个字典,用来保存每个数字所代表的字符串,然后我们还需要一个变量level,记录当前生成的字符串的字符个数,实现套路和上述那些题十分类似,

https://github.com/jianminchen/Leetcode_C-/blob/master/LetterCombinationOfAPhoneNumber.cs

18 4 sum

19 Remove Nth Node From End of List

20 Valid Parentheses

http://blog.csdn.net/fightforyourdream/article/details/13011825

C# code:
https://github.com/jianminchen/Leetcode_C-/blob/master/20ValidParentheses.cs
January 20, 2016
https://github.com/jianminchen/Leetcode_C-/blob/master/20ValidParentheses_B.cs

favorite blogs to read: January 20, 2016
http://bangbingsyb.blogspot.ca/2014/11/leetcode-valid-parentheses.html

http://www.acmerblog.com/leetcode-solution-valid-parentheses-6316.html

http://blog.csdn.net/foreverling/article/details/49685177?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

http://segmentfault.com/a/1190000003481208

http://harrifeng.github.io/algo/leetcode/valid-parentheses.html

http://www.jiuzhang.com/solutions/valid-parentheses/

So, ready to work on the next algorithm about parentheses:
Leetcode 32: longest valid parentheses -
http://codeganker.blogspot.ca/2014/03/longest-valid-parentheses-leetcode.html