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.
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Wednesday, October 28, 2015
Leetcode question 241: Different ways to add parentheses
Labels:
DP,
memorization,
parentheses,
动态规划
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment