首页 > 其他 > 详细

leetcode970

时间:2019-01-22 11:18:46      阅读:200      评论:0      收藏:0      [点我收藏+]
public class Solution
    {
        public IList<int> PowerfulIntegers(int x, int y, int bound)
        {            
            var list = new List<int>();
            for (int i = 0; i < bound; i++)
            {
                for (int j = 0; j < bound; j++)
                {
                    var num =
                        Math.Pow((double)x, (double)i)
                        +
                        Math.Pow((double)y, (double)j);
                    if (num <= bound)
                    {
                        list.Add((int)num);
                    }
                    else
                    {
                        if (j == 0)
                        {
                            return list.Distinct().OrderBy(a => a).ToList();
                        }
                        else
                        {
                            break;//换行
                        }
                    }
                }
            }
            return list.Distinct().OrderBy(a => a).ToList();
        }
    }

 

leetcode970

原文:https://www.cnblogs.com/asenyang/p/10302632.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!