ISO M.CodD
JF-Expert Member
- Feb 17, 2013
- 8,139
- 17,612
Ni bora kutumia pastebin kama codepad.org kutuma code.def Equilibrum(ArrayList):
N = len(ArrayList)
EquilibrumIntegers = [ ]
for P in range(0, N+1):
lowerBound = ArrayList[0😛]
upperBound = ArrayList[P+1:N+1]
if sum(lowerBound) == sum(upperBound):
EquilibrumIntegers.append(P)
if EquilibrumIntegers == [ ]:
return -1
else:
return EquilibrumIntegers
Kama ukiamua kui test kwenye interactive shell keep in mind the indentation maana ni muhimu kwenye python.Ukizingua indentation inaweza is execute hzo nested statements
Pia hyo range( ) function happy juu bro nimetumia python 2.7.Uki run kwenye python 3.0 Ina generate iterative construct na cyo list
So I test kwenye python version less than 3.0
Kama hauna hzo version less than 3.0 then I force I generate list kwa kuongezea Neno list mbele
Have a nice day.
Ni bora kutumia pastebin kama codepad.org kutuma code.
This is an algorithmic problem - complete with time and space complexity. Kama ndio unajifunza programming in python then angalia resources unazotumia. Hili swali hukutakiwa ukumbane nalo.
Hamna time na space complexities yoyote kwenye hhyo task.Any Turing based machine Ina solve(unge calculate O( ) yake kabla ya kutumia maneno mazito hayo)
Mkuu Graph
Nimetuliza kichwa hapa nimeona solution uliyo provide inaeleweka kwa urahisi.
Hebu ngoja ni solve index 3 nione kama solution itakuwa sawa na current_sum
Current_sum = -2 (hii nimepata kama ulivyonielekeza sum ya index ilipofikia)
Total_sum - current_sum - current_element = 1- (-2) - 5
The answer is -2 ambayo ni sawa na current_sum kwa maana hii -2 is equilibrium
Mkuu Graph let me know if I'm correct.
total_sum = sum(list)
current_sum = 0
for i in range 0 to last_index
current_element = list[i]
if(total_sum - current_sum - current_element == current_sum)
//its equllibrium add to list
current_sum += current_element
if equillibrium_list is empty return -1
else return equllibrium_list
Mkuu mimi ndiyo kwanza naanza and I have convinced myself python won't be as much complicated as people want me to believe.Ukitaka kuifahamu code vizuri fahamu alama zote na maana halisi.
Mi nimesoma C++ nikaja kufundishwa implementation of data structure kwa java. Ilinisumbua sana mpaka Leo nikimkumbuka Dr. Yule naudhika sana. Komaa tu polepole
Aina noma bro.Unaonekana una challenges nzuri Sana huko.Tuma challenges nyengine bro kama vipi hats zoteMkuu Kart godel shukran sana. I've learnt from your contributions. And thanks for the attachment. Thumb up!
Onyesha calculations zinazoonyesha kuwa hyo algorithm ni O(n^2) maana naona unaongea siasa tu
1. for P in range(0, N+1):
2. lowerBound = ArrayList[0:p]
3. upperBound = ArrayList[P+1:N+1]
4. if sum(lowerBound) == sum(upperBound):
5. EquilibrumIntegers.append(P)
We si hua ni mzee wa matusi tu, nakukumbuka sana ulinitukania mama, baba, familia yangu yote kwa kua tu nilikwambia ukweli. Ulisema wewe ni genius, umeshindwa kutambua hiyo algorithm kama ni O(n^2) alafu ukasema nina IQ ya sijui mnyama gani? hehe acha utani, ni algorithm rahisi sana haiwezi kukushinda we genius hata siku moja.
Sasa ngoja mimi kilaza nikusaidie genius.
Code:1. for P in range(0, N+1): 2. lowerBound = ArrayList[0:p] 3. upperBound = ArrayList[P+1:N+1] 4. if sum(lowerBound) == sum(upperBound): 5. EquilibrumIntegers.append(P)
angalia line 1, it runs n times, alafu line 4, it runs n times kwa kua umeita sum(lowerBound) na sum(upperBound) ambazo zote hizi zina run n times, hii ni sawa na kuandika nested for loops. Kwa kila P, sum function itarun n times, sasa kutoka 0 to n+1 si ni sawa na n^2?
Kumkamata mtu anayejifanya kua na majigambo hua ni rahisi sana, muache tu ipo siku atateleza, nilikua na ujinga kama wako wa kudharau watu ila angalau I didn't show it on the outside kutukana ovyo, mwisho wa siku nikajifunza kushirikiana na watu, now I am a better person living my dream. Punguza dharau dogo genius.
Swali zima umelisoma bila shaka. Au sijakuelewa?Hamna time na space complexities yoyote kwenye hhyo task
Complexity:
expected worst-case time complexity is O(N);expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
Elements of input arrays can be modified.