algorithm
æ¿å ¥ã½ã¼ãã®ã¢ã«ã´ãªãºã ä¸ããããé åãã½ã¼ãããéãæ¿å ¥ã½ã¼ããç¨ããã¨ããã ä¸ããããé åããã½ã¼ãæ¸ã¿ã®é å(é·ãã¯1)ã¨æªã½ã¼ãã®é åã«åå²ãããæªã½ã¼ãã®é åã®ä¸ããä¸ã¤é¸ã³ãã½ã¼ãæ¸ã¿ã®é åã«æ¿å ¥ãããæ¿å ¥ãããå¤ã¨ãé£ãåãè¦â¦
é åã®ç©åæ¼ç®ã®ã¢ã«ã´ãªãºã ãç¹å¥ãªé åããä¸ããããã®ã§ç©åæ¼ç®ãè¡ã£ã¦å¤ãè¿ãããç¹å¥ãªé åãã¯æ°å¤ãããã¯ãç¹å¥ãªé åãããã¤ããç¹å¥ãªé åãå ã®æ°å¤ããã¹ã¦å ç®ãããããã¹ãã¬ãã«ã«å¿ãã¦ãã®åãä¹ç®ããã ä¾ãã°ã [x, y] â x + yâ¦
äºåæ¢ç´¢æ¨(binary search tree)ããè¿ä¼¼å¤ãæ±ãã äºåæ¢ç´¢æ¨ã®ãã¼ã¿ã¨targetãä¸ãããããäºåæ¢ç´¢æ¨ã®ãã¼ã¿ã®ä¸ããtargetã®è¿ä¼¼å¤ãæ±ããã ä¾ãã°æ¬¡ã®ãããªäºåæ¢ç´¢æ¨ã®ãã¼ã¿ã¨target 5ãä¸ããããã¨ããçãã¯6ã§ããã 8 /\ 3 10 /\ \ 1 6 14â¦
2ã¤ã®æ°ã®å 2ã¤ä»¥ä¸ã®ã¦ãã¼ã¯ãªæ°åã®éåAã®ä¸ãããã¿ã¼ã²ãã(target)ã®æ°åã®åã¨ãªãæ°åã®ãã¢ãè¦ã¤ãåºããæ°åã®ãã¢ã¯æ大1ã¤ãããçãã¯å¤ãå°ããé ã«ä¸¦ã¹ãã¨ããã ä¾ãã°Aã1, 10, 5, -1ã12ãtargetã15ã§ããã°ãçãã¯10, 5ã®ãã¢ã§ãâ¦
ãã¤ããªãµã¼ã å: ã½ã¼ããããæ°å¤ã®é åã¨æ°å¤targetãåãåããé åä¸ã®targetã®ã¤ã³ããã¯ã¹ãæ±ããããã®éããã¤ããªãµã¼ããç¨ãããã¨ã ã¢ã«ã´ãªãºã å®è£ $O(\log n)$ é åã®è¦ç´ æ°ãnã¨ããã¨ããleft=0ãright=nã®å¤æ°ãä½ããã¾ããleftã¨riâ¦
Palindrome Check (åæãã§ãã¯) ã¢ã«ã´ãªãºã æååstringãåãåã£ã¦ãåæãã©ããããã§ãã¯ããããã¹ã¦ã®æåãæ¯è¼ããªãã¨ãããªãã®ã§ãã©ããã£ã¦ãè¨ç®éã$O(n)$以ä¸ã«ãªãã¯ãã ã¢ã«ã´ãªãºã å®è£ (1) $O(n)$ 両端ããæåãçãããæ¯è¼ãã¦â¦
ãã£ããããæ°åã®ã¢ã«ã´ãªãºã åå¼·ãã¦ãã¡ã¢ ãã£ããããæ°åã¨ã¯ ããã£ããããæ°åãã¨ã¯ãåã®ï¼ã¤ã®æ°ãå ããã¨æ¬¡ã®æ°ã«ãªããã¨ããæ°åã1çªç®ã¯0ã2çªç®ã¯1ãnçªç®ã®æ°åã¯(n - 1)çªç®ã¨(n - 2)çªç®ã®æ°åã®åã ä¾ãã°ã6çªç®ã®æ°ã¯5 (0, 1, â¦