练练脑,继续过Hard题目

http://www.cnblogs.com/charlesblc/p/6384132.html

继续过Hard模式的题目吧。

 

 #TitleEditorialAcceptanceDifficultyFrequency 
 。65Valid Number   12.6%Hard 
 。126Word Ladder II   13.6%Hard 
 。149Max Points on a Line   15.6%Hard 
 。146LRU Cache   16.0%Hard 
 。68Text Justification   18.1%Hard 
 。460LFU Cache   19.0%Hard 
 。44Wildcard Matching   19.0%Hard 
 。308Range Sum Query 2D - Mutable   19.8%Hard 
 。4Median of Two Sorted Arrays   20.8%Hard 
 。420Strong Password Checker   21.0%Hard 
 。273Integer to English Words   21.1%Hard 
 。30Substring with Concatenation of All Words   21.7%Hard 
 。440K-th Smallest in Lexicographical Order   22.1%Hard 
 。140Word Break II   22.2%Hard 
 。212Word Search II   22.2%Hard 
 。269Alien Dictionary   22.3%Hard 
 。174Dungeon Game   22.9%Hard 
 。214Shortest Palindrome   23.0%Hard 
 。446Arithmetic Slices II - Subsequence   23.0%Hard 
 。32Longest Valid Parentheses   23.1%Hard 
 。295Find Median from Data Stream   23.3%Hard 
 。132Palindrome Partitioning II   23.4%Hard 
 。10Regular Expression Matching   23.6%Hard 
 。76Minimum Window Substring   23.8%Hard 
 。188Best Time to Buy and Sell Stock IV   23.8%Hard 
 。321Create Maximum Number   23.9%Hard 
 。135Candy   23.9%Hard 
 。335Self Crossing   23.9%Hard 
 。97Interleaving String   23.9%Hard 
 。391Perfect Rectangle   24.2%Hard 
 158Read N Characters Given Read4 II - Call multiple times   24.4%Hard 
 466Count The Repetitions   24.6%Hard 
 336Palindrome Pairs   24.7%Hard 
 41First Missing Positive   24.9%Hard 
 124Binary Tree Maximum Path Sum   25.0%Hard 
 224Basic Calculator   25.5%Hard 
 218The Skyline Problem   25.5%Hard 
 84Largest Rectangle in Histogram   25.6%Hard 
 23Merge k Sorted Lists   25.9%Hard 
 45Jump Game II   26.0%Hard 
 85Maximal Rectangle   26.1%Hard 
 57Insert Interval   26.3%Hard 
 138Copy List with Random Pointer   26.6%Hard 
 233Number of Digit One   27.3%Hard 
 381Insert Delete GetRandom O(1) - Duplicates allowed   28.0%Hard 
 37Sudoku Solver   28.1%Hard 
 432All O`one Data Structure   28.2%Hard 
 87Scramble String   28.3%Hard 
 123Best Time to Buy and Sell Stock III   28.3%Hard 
 56Merge Intervals   28.4%Hard 
 282Expression Add Operators   28.5%Hard 
 316Remove Duplicate Letters   28.6%Hard 
 164Maximum Gap   28.6%Hard 
 99Recover Binary Search Tree   28.7%Hard 
 327Count of Range Sum   28.9%Hard 
 51N-Queens   29.0%Hard 
 25Reverse Nodes in k-Group   29.7%Hard 
 472Concatenated Words   30.1%Hard 
 465Optimal Account Balancing   30.1%Hard 
 248Strobogrammatic Number III   30.5%Hard 
 72Edit Distance   30.6%Hard 
 115Distinct Subsequences   30.6%Hard 
 403Frog Jump   30.9%Hard 
 411Minimum Unique Word Abbreviation   31.1%Hard 
 239Sliding Window Maximum   31.4%Hard 
 330Patching Array   31.5%Hard 
 297Serialize and Deserialize Binary Tree   31.6%Hard 
 354Russian Doll Envelopes   31.8%Hard 
 358Rearrange String k Distance Apart   31.8%Hard 
 33Search in Rotated Sorted Array   31.9%Hard 
 363Max Sum of Rectangle No Larger Than K   32.1%Hard 
 410Split Array Largest Sum   32.2%Hard 
 480Sliding Window Median   33.1%Hard 
 317Shortest Distance from All Buildings   33.3%Hard 
 117Populating Next Right Pointers in Each Node II   33.5%Hard 
 315Count of Smaller Numbers After Self   33.5%Hard 
 301Remove Invalid Parentheses   34.5%Hard 
 42Trapping Rain Water   35.3%Hard 
 128Longest Consecutive Sequence   35.3%Hard 
 329Longest Increasing Path in a Matrix   35.4%Hard 
 407Trapping Rain Water II   35.6%Hard 
 154Find Minimum in Rotated Sorted Array II   36.2%Hard 
 265Paint House II   37.1%Hard 
 272Closest Binary Search Tree Value II   37.6%Hard 
 291Word Pattern II   37.7%Hard 
 305Number of Islands II   38.1%Hard 
 380Insert Delete GetRandom O(1)   38.4%Hard 
 145Binary Tree Postorder Traversal   38.4%Hard 
 340Longest Substring with At Most K Distinct Characters   38.6%Hard 
 352Data Stream as Disjoint Intervals   38.9%Hard 
 159Longest Substring with At Most Two Distinct Characters   39.7%Hard 
 312Burst Balloons   41.6%Hard 
 287Find the Duplicate Number   41.8%Hard 
 425Word Squares   41.9%Hard 
 52N-Queens II   42.8%Hard 
 302Smallest Rectangle Enclosing Black Pixels   44.0%Hard 
 471Encode String with Shortest Length   44.2%Hard 
 296Best Meeting Point   50.4%Hard

 

97Interleaving String   23.9%Hard

这道题目很好,是使用DP的典型方案。可惜我开始还是没能做出来。Discuss的解法非常好。好好学习。

bool isInterleave(string s1, string s2, string s3) {
    
    if(s3.length() != s1.length() + s2.length())
        return false;
    
    bool table[s1.length()+1][s2.length()+1];
    
    for(int i=0; i<s1.length()+1; i++)
        for(int j=0; j< s2.length()+1; j++){
            if(i==0 && j==0)
                table[i][j] = true;
            else if(i == 0)
                table[i][j] = ( table[i][j-1] && s2[j-1] == s3[i+j-1]);
            else if(j == 0)
                table[i][j] = ( table[i-1][j] && s1[i-1] == s3[i+j-1]);
            else
                table[i][j] = (table[i-1][j] && s1[i-1] == s3[i+j-1] ) || (table[i][j-1] && s2[j-1] == s3[i+j-1] );
        }
        
    return table[s1.length()][s2.length()];
}
View Code

 

 

391Perfect Rectangle   24.2%Hard

这道题目很难。而这个解法,真是太巧了。

两个基本点:一是总面积等于各个区域面积之和;另一个是所有的点出现偶数次,除了四个角上面的点。

View Code

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值